# Answer to Question #16258 in C# for sibusiso

Question #16258
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. Important Notes 1. The numbers A and B must be different. The program should keep asking for new inputs until it gets two different numbers. 2. A and/or B could be negative. The program should work with negative values. 3. The numbers A and B could be given in either order (A < B or A > B). The program should not care and be able to accept them in either order. 4. The program should pick a number at random between A and B inclusive (the random number might be either A or B). 5. The program should tell the user if a guess is
1
2012-10-10T11:37:29-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

{
class Program
{
& static void Main(string[] args)
& {
Random _random = new Random(DateTime.Now.Millisecond);

int _secretNumber = 0;
int _a=0;
int _b=0;

Console.WriteLine(_secretNumber);

bool _check=false;
do
{
try
{
& Console.Write("Enter A");

& Console.WriteLine();

& Console.Write("Enter B");
& if (_a != _b)
_check = true;
& else
& {
Console.WriteLine("The numbers A and B must be different.");
_check = false;
& }
}
catch
{
& Console.WriteLine("Try againe");
& _check = false;
}
} while (!_check);

if (_a < _b)
_secretNumber = _random.Next(_a, _b + 1);
else
_secretNumber = _random.Next(_b, _a + 1);
_check = true;

int _guess = 0;

Console.WriteLine("I guess number. Guess it");
do
{
try
{
& if (_guess == _secretNumber)
& {
_check=false;
& }
& else
& {
if (_guess > _secretNumber)
{
Console.WriteLine("It's to high");
_check = true;
}
else
{
Console.WriteLine("It's to low");
_check = true;
}
& }
}
catch
{
& _check = false;
}
} while (_check);

Console.WriteLine("You winn");
& }
}
}

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!