Well, what I'm trying to do seems pretty simple, but it doesn't work the way I want it. I know that I'm just not getting anything. In fact, I'm trying to read console input, assign it to a variable. Then I want to check this variable to see if it is a valid number. If this is not the case, I want to tell the user that it is not valid, and run the loop again until I get a real number, and then exit. Here is my code, could you help me understand what I am doing wrong?
const int AVERAGE_IQ = 100;
int userIQ;
bool done = false;
do
{
Console.Write("Please enter an IQ Score between 1 and 200: ");
userIQ = Convert.ToInt32(Console.ReadLine());
if (userIQ == 0 || userIQ >= 200)
{
Console.WriteLine("You have entered an invalid IQ Score, please try again.");
done = false;
}
else if (userIQ >= AVERAGE_IQ)
{
Console.WriteLine("{0} is an above average IQ.", userIQ);
done = true;
break;
}
else if (userIQ <= AVERAGE_IQ)
{
Console.WriteLine("{0} is an below average IQ.", userIQ);
done = true;
break;
}
else if (userIQ == AVERAGE_IQ)
{
Console.WriteLine("{0} is anaverage IQ.", userIQ);
done = true;
break;
}
} while (done =! true);
source
share