In: Computer Science
Please code C#
6. Write a program that generates a random number between 0 and 10 and asks the user to guess that number. The program then informs the user if they guessed correctly or incorrectly then displays the correct answer.
Solution
Code
using System;
public class NumberGuess
{
public static void Main()
{
int rnumber = new Random().Next(0, 10);
Console.WriteLine("Please enter the number between 0 and 10 to
guess");
while(true)
{
if (int.Parse(Console.ReadLine()) == rnumber)
break;
Console.WriteLine("U guessed incorretly");
}
Console.WriteLine("U guessed correctly");
}
};
Screenshot
Output
--
all the best