namespace Guess_a_number { //4- Write a program that picks a random number between 1 and 10. Give the user 4 chances to guess the number. //If the user guesses the number, display “You won"; otherwise, display “You lost". //(To make sure the program is behaving correctly, you can display the secret number on the console first.) class Program { static void Main(string[] args) {
var random = new Random(); var randomNumber = random.Next(1, 10);
//Console.WriteLine("The magic number is {0}.", randomNumber);
for (var i = 3; i >= 0; i--) { Console.WriteLine("Guess the magic number between 1 to 10: "); var guess = Convert.ToInt32(Console.ReadLine());
if (randomNumber != guess) { Console.WriteLine("You lost! You have {0} magical attempts left.", i); continue; } else { Console.WriteLine("You won! A magical fairy will visit you in your dreams tonight."); } break; } } } }


















