I'm developing a practice program that simply converts a temperature value from fahrenheit to celsius when the user enters an integer, selects a radio button and then clicks a button.
I'm having trouble testing if the user has selected a radio button. In the click event method for the calculate button, an if statement tests if the text box is empty and displays a message in a result label if it is (this works). If there is a valid entry, then a second if statement checks if neither of the radio buttons is checked, and if that is the case, it should display a message to that effect in the result label. This is not working.
If no radio button is selected, the program does nothing. Here's the code:
if (textBox.Text == "") labelResult = "Please enter a temperature to convert."; else if ((radiobutton1.Checked == false) && (radiobutton.Checked == false) labelResult = "Please select a conversion type to perform": else calculateMethod();
The code compiles, but again, it's as if the second condition is not being tested. I can't tell if the problem is with the second "if" expression, or of the code block is not written correctly. I could just set one of the radio buttons to be automatically selected when the program runs, but I thinkI may need to perform this kind of task in another, future situation, so I want to know what I'm doing/not doing.