how do you create a program that first asks for two integer values A and B. Your program should
then pick a random number between A and B and keep it secret. Then ask the user to
guess what the number is. The program should continue to ask the user to guess, until
the user gets the correct answer. Each time the user makes an incorrect guess, the
program should tell the user if the guess was too high, or too low. The program should
also tell the user if the guess was outside the range between A and B.
1
Expert's answer
2011-10-13T13:11:24-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace questions_CSharp {
class Program { & static void Main(string[] args) & { int A = 0, B = 0, C = 0, userNumber = 0; Random rand = new Random(); Console.Write("Please, enter A: "); A = Convert.ToInt32(Console.ReadLine());
Console.Write("Please, enter B: "); B = Convert.ToInt32(Console.ReadLine()); C = rand.Next(A, B); Console.WriteLine("Secret Number is generated!"); Console.WriteLine("Try to guess it!"); while (true) {
{ & Console.WriteLine("Congratulations! Your Answer is right!"); & break;
} if (userNumber < A || userNumber > B) Console.WriteLine("Number is outside the range between A and B. Try Again!"); if (userNumber < C) Console.WriteLine("Number is to low"); if (userNumber > C) Console.WriteLine("Number is to high"); } Console.WriteLine("Have a nive day. To exit press any button..."); Console.ReadKey(); & } } }
Comments
Leave a comment