using System; class ApplicationEntry { static void Main(string[] args) { bool repeat = true, repeat2 = true, repeat3 = true; while (repeat == true) { repeat2 = true; Random r = new Random(); int numb = (r.Next(20, 30)); while (repeat2 == true) { Console.WriteLine("Please enter a numbers between 20 and 30"); int guess1 = Convert.ToInt32(Console.ReadLine()); if ((guess1 < 20 || guess1 > 30) && guess1 != numb) { Console.WriteLine("Invalid. Please enter a number between 20 and 30"); repeat3 = false; } else if (guess1 == numb) { Console.WriteLine("Good job"); repeat2 = false; repeat3 = true; } else { Console.WriteLine("Wrong! Try again"); repeat2 = true; repeat3 = false; } while (repeat3 == true) { Console.WriteLine("Would you like to play again?"); string answer = Console.ReadLine(); if (answer == "yes" || answer == "Yes" || answer == "YES") { repeat3 = false; repeat = true; repeat2 = false; } else if (answer == "no" || answer == "No" || answer == "NO") { repeat = false; repeat3 = false; } else { Console.WriteLine("I didn't understand that"); } } } } Console.Write("\nPress any key to exit program: "); Console.ReadKey(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)