Can not break out of While loop.

M

Mike Langworthy

I am having a problem Breaking out of the while loop, it never terminates.
any suggestions

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Random random = new Random();
int returnValue = random.Next(1, 100);
Console.WriteLine(returnValue);

int Guess = 0;
int i = 0;

Console.WriteLine("Welcome to the Guessing game. Please Choose
a Number between 1 and 100.");

while(Guess != returnValue)
{
Guess = Convert.ToInt32(Console.Read());

if (Guess <= returnValue - 75)
{
Console.WriteLine("You are so low you are in
Hell.");
}
if (Guess <= returnValue - 50 )
{
Console.WriteLine("Put the Shovel down, you are too
Low.");
}
if (Guess < returnValue )
{
Console.WriteLine("Woah buck, too low Try again");
}
if (Guess >= returnValue + 75 )
{
Console.WriteLine("Hey Flyboy, get your head out of
the clouds");
}
if (Guess >= returnValue + 50 )
{
Console.WriteLine("Get off the damn roof you are too
high");
}
}
Console.WriteLine("Congratulations, you win ");
Console.WriteLine("Press Enter to terminate...");
Console.Read();

}




}
}
 
V

Vince A

You probably have already figured this out by this time...

Console.Read() is reading what's typed in as a series of strings, and not as
a single integer.
Each individual character is being converted to integer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top