c# - If-else statement with radio buttons and a for loop -
i've gotten issue keeps happening , i'm unsure problem is. need create program in microsoft visual studio radiobutton1 finding sum of consecutive numbers , radiobutton2 finding factorial of number.
there 3 buttons, 1 for loop, 1 while loop, , 1 do-while loop. i'm working on button.
what i'm trying making selection, pressing 1 of buttons, it'll find answer using loop clicked in message box.
this i've gotten far:
private void button1_click(object sender, system.eventargs e) { if ((radiobutton1.checked == true) && (radiobutton2.checked == false)) { int sum = 0; int number = int.parse(numericupdown1.value.tostring()); (int = 1; <= number; i++) { sum = sum + i; messagebox.show("the sum of consecutive numbers leading " + number + " " + sum + "."); } messagebox.show("the sum of consecutive numbers leading " + number + " " + sum + "."); } else if ((radiobutton2.checked == true) && (radiobutton1.checked == false)) { int product = 1; int number = int.parse(numericupdown1.value.tostring()); (int = 1; <= number; i++) { product *= i; messagebox.show("the factorial of numbers leading " + number + " " + product + "."); } messagebox.show("the factorial of numbers leading " + number + " " + product + "."); } else { messagebox.show("invalid"); } }
i keep receiving message:
"'lab5'does not contain definition 'radiobutton2.checkedchanged' , no extension method 'radiobutton2.checkchanged' accepting first argument of type 'lab5' found (are missing using directive or assembly reference?)."
and have no idea means.
any appreciated.
i want keep in if-else statement because don't want message box radiobutton1 pop when radiobutton2 selected.
you have inadvertently added handler radio button (e.g. double clicking in designer) , removed it. when solution building, looking function can't find it.
check lab5.designer.cs radiobutton2 code. this:
this.radiobutton1.autosize = true; this.radiobutton1.location = new system.drawing.point(102, 162); this.radiobutton1.name = "radiobutton1"; this.radiobutton1.size = new system.drawing.size(85, 17); this.radiobutton1.tabindex = 1; this.radiobutton1.tabstop = true; this.radiobutton1.text = "radiobutton1"; this.radiobutton1.usevisualstylebackcolor = true; this.radiobutton1.checkedchanged += new system.eventhandler(this.radiobutton1_checkedchanged); /* offending line! */
that last line trying add event handler referencing non-existant method. can either remove here.
also, when program builds, should able double-click on compile error , ide take source of problem.
Comments
Post a Comment