Answer the question
In order to leave comments, you need to log in
Use of switch together with RadioButton (and incorrect work of switch)?
Good afternoon :)
There was a problem in using the Switch operator.
There is a code that, accordingly, works with If:
private: System::Void otvetButton_Click(System::Object^ sender, System::EventArgs^ e) {
double a, b, I, F, x;
int n;
a = Convert::ToDouble(aPredelText->Text);
b = Convert::ToDouble(bPredelText->Text);
n = Convert::ToInt32(nText->Text);
if (constRadioButton->Checked) {
F = f(x);
I = Integr(a, b, n);
}
if (stepenRadioButton->Checked) {
I=155; //переменная пока вставлена для проверки работы
}
otvet->Text = I.ToString("n");
}
private: System::Void otvetButton_Click(System::Object^ sender, System::EventArgs^ e) {
double a, b, I, F, x;
int n;
a = Convert::ToDouble(aPredelText->Text);
b = Convert::ToDouble(bPredelText->Text);
n = Convert::ToInt32(nText->Text);
switch (n)
{
case '1': {
F = f(x);
I = Integr(a, b, n);
}
break;
case '2':
I=155;
break;
}
otvet->Text = I.ToString("n");
}
Answer the question
In order to leave comments, you need to log in
First - why the switch broke - remove the quotes. C++ treats your '1' as the number 49 (ASCII character code 1).
The second is how to make a switch react to a radiobutton - I haven't used the VCL for a long time, but it's possible that the groupBox in which your switches are located can find out which one is selected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question