Chapter 4 Exercise 4.2 PLEASE HELP
Okay, So I tried to do this and couldn't figure it out, I went to the appendix, and still do not understand why this is operating this way? I copied the code below with questions. If someone can maybe re paste with the answers next to each line I will greatly appreciate it!
THE QUESTION IS, Write an application that includes the logic from exercise1, obtains two numbers from the user, and displays them, but rejects any input where both numbers are greater than 10 and asks for two new numbers.
static void Main(string[] args)
{
bool numbersOK = false; //I don't understand what this is declared for
double var1, var2;
var1 = 0;
var2 = 0;
while (!numbersOK) //I don't understand what this test is performing
{
Console.WriteLine("Give me a number:");
var1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Give me another number:");
var2 = Convert.ToDouble(Console.ReadLine());
if ((var1 > 10) && (var2 > 10))
{
Console.WriteLine("Only one number may be greater than 10.");
}
else
{
numbersOK = true; //I don't understand why this is making it move on to the next line of code below
}
}
Console.WriteLine("you entered {0} and {1}", var1, var2);
Console.ReadKey();
Last edited by NewbySwaj; November 24th, 2013 at 05:31 PM..
|