+ 1
how to make the "writeline" in a loop run only once
int num = 0; Random example = new Random(); num = example.Next(1, 1001); String X = Console.ReadLine(); int Y = Convert.ToInt32(X); if (Y>num) { Console.WriteLine("Larger"); } else if(Y<num) { Console.WriteLine("Smaller"); } else { Console.WriteLine(Y); } Console.Read();
3 Answers
+ 5
At first there wasn't code...now:
: There's no loop here.
: Can you add the loop you want to use?
: Also, should the loop continue after printing or do you want to break out of it?
+ 4
The answer you posted does what you want already...by default...because 1002 is > than the maximum value the Next() function generates. I'm guessing this wasn't a question then...
+ 2
int num = 0;
Random example = new Random();
num = example.Next(1, 1001);
String X = Console.ReadLine();
int Y = Convert.ToInt32(X);
do
{
if (Y > num)
Console.WriteLine("Larger");
else if (Y < num)
Console.WriteLine("Smaller");
else
Console.WriteLine(Y);break;
} while (num ==1002);