Answer to Question #344740 in C# for miya

Question #344740

)Write a program that generates a random number between 1 and 10 inclusive. Ask a user to guess the random number, then display a message indicating whether the user’s guess was too high, too low, or correct.

• The message “Sorry – your guess was too low!” should be displayed if the number entered by the user is lower than the random number generated

• The message “Sorry – your guess was too high!” should be displayed if the number entered by the user is higher than the random number generated.

• The message “Congratulations – your guess is correct!” should be displayed if the number entered by the user matched the random number generated.


1
Expert's answer
2022-05-26T14:08:29-0400
using System;
class Program
{
    static void Main(string[] args)
    {
        Random rnd = new Random();
        int value = rnd.Next(1, 11);
        string str;
        int Number = 0;
        Console.WriteLine("Please guess a random number");
        while (Number != value)
        {
            str = Console.ReadLine();
            if (int.TryParse(str, out Number))
                if (Number >= 1 && Number <= 10)
                    if (Number == value)
                        Console.WriteLine("Congratulations – your guess is correct!");
                    else if (Number < value)
                        Console.WriteLine("Sorry – your guess was too low!");
                    else if (Number > value)
                        Console.WriteLine("Sorry – your guess was too high!");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS