Answer to Question #29206 in C# for terror

Question #29206
a program that first asks for two integer values A and B,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
2013-04-26T11:48:25-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuessNumber
{
class Program
{
static void Main(string[] args)
{
int A,B;//declare A and b
int inputnumber = 0;//input number
Console.Write("Enter number A: ");
A = int.Parse(Console.ReadLine());//input number A
Console.Write("Enter number B: ");
B = int.Parse(Console.ReadLine());//input number B

Random rand=new Random();
int guessnumber = rand.Next(A, B);//Random number
while (inputnumber != guessnumber) {
Console.Write("What the number is: ");
inputnumber = int.Parse(Console.ReadLine());//read number
if (inputnumber < guessnumber)
{
Console.WriteLine("Too low!!!");//show Too low
}
else if (inputnumber > guessnumber)
{
Console.WriteLine("Too high!!!");//show Too high
}else{
break ;
}

if (inputnumber < A && inputnumber > B) {
Console.WriteLine("Quess was outside the range between A and
B");//Quess was outside the range between A and B
}
}
Console.WriteLine("You are right!!!");//show You are right
Console.WriteLine("");
Console.WriteLine("Press any key to exit...");//Press any key to exit
Console.ReadLine();


}
}
}

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