Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Validate user input in Console App
Antony García
Jan 13 2017 12:19 PM
245
Reply
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);
*************************************************************
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
How to avoid Boxing and UnBoxing in C#?
how to do typecasting of json data