S
S
Satiata2015-01-14 16:27:35
C++ / C#
Satiata, 2015-01-14 16:27:35

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");

}

And I need that when one of several radio buttons is pressed, a certain case in the switch works. How can this be done?
And, to be honest, there is a small problem in the form of the fact that I tried to just start the switch in order to try if it would work. It looked like this:
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");

}

those. depending on the value of the variable n entered by me, a certain case should have been selected. But this does not happen, and as a result, I get 0.00 in the answer text field.
What is wrong and what needs to be corrected?
They didn’t ban me on Google, I just didn’t find my problem there :) And all that is, in whatever languages, is in C # and a little in a version that I don’t need :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2015-01-14
@Satiata

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 question

Ask a Question

731 491 924 answers to any question