66 884
Assignments Done
99,1%
Successfully Done
In October 2018

Answer to Question #4646 in C# for richard rooks

Question #4646
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.
Expert's answer
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.Write("Your Answer: ");
userNumber =
Convert.ToInt32(Console.ReadLine());

if (userNumber == C)

{
& 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();
&
}
}
}

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions