mercredi 25 février 2015

if statements in while loops

I am new to programming, and I am trying to practice various functions with a simple "Pick a Number" application. However I have ran into a problem.



Random rnd = new Random();
int deNumero = rnd.Next(1,100001);
while (true)
{
Console.WriteLine("Pick a number 1 - 100000");
string input = Console.ReadLine();
int numero = Int32.Parse(input);
if(numero < deNumero)
{
Console.WriteLine("Lower");
}
else if(numero > deNumero)
{
Console.WriteLine("Higher");
}
else if(numero == deNumero)
{
Console.WriteLine("Well done!");
Console.ReadKey();
}
else
{
Console.WriteLine("What?");
}
}


Let's say I pick a number that is greater than deNumero and it prints "Lower". Where I am seeing a problem is when I pick the number 1, it will print "Lower" again. it keeps going to the same if statement even when it shouldn't. What am I doing wrong?


Aucun commentaire:

Enregistrer un commentaire