Guest User

Guest User

  • Tech Writer
  • 71
  • 6.6k

Validate user input in Console App

Jan 13 2017 12:19 PM
Hi...How can I validate user input when the user's input is greater than 10.
I mean, in this code below if the user introduce a value greater than 10, I want to print a message on screen. What operator or comparision should I use and where?..Here is the code:
 
 
 ********************************************************
private static void GusssingGame()
{
Console.Clear();
Console.WriteLine(" ***** GUESS THE NUMBER GAME ******");
Random myRandom = new Random();
int randomNumber = myRandom.Next(1, 11);
int intentos = 0;
bool incorrect = true;
do
{
Console.Write("Choose a number between 1 and 10 and press ENTER: ");
string result = Console.ReadLine();
intentos++;
if (result == randomNumber.ToString())
{
incorrect = false;
}
else
{
Console.WriteLine("Incorrect. Try again!");
}
} while (incorrect == true);
 *************************************************************

Answers (3)