TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
71
6.5k
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);
*************************************************************
Reply
Answers (
3
)
How to avoid Boxing and UnBoxing in C#?
how to do typecasting of json data