65 788
Assignments Done
99,4%
Successfully Done
In October 2018

Answer to Question #4651 in C# for bob

Question #4651
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 outside the range between A and B.
6. The program should tell the user if a guess within the range is higher or lower than
the secret number.
7. The program should end when the correct number is guessed.
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Continuenumber
{
class Program
{
& private static int numberA;
& private static int numberB;
& private static int continuerandomnumber;
& private static Random randomnumber=new Random();
& private static int userEnter;
& /// <summary>
& /// Enter number A and B
& /// </summary>
& private static void EnterNumber() {
try
{
Console.Write("Enter number A: ");
numberA = int.Parse(Console.ReadLine());
Console.Write("Enter number B: ");
numberB = int.Parse(Console.ReadLine());
if (numberA < numberB)
{
& continuerandomnumber = randomnumber.Next(numberA, numberB);
& do
& {
Console.Write("Enter your answer:");
userEnter = int.Parse(Console.ReadLine());
if (userEnter > continuerandomnumber && userEnter > numberA && userEnter < numberB)
{
Console.WriteLine("You entered bigger number than computer& generated");
}
else if (userEnter < continuerandomnumber && userEnter > numberA && userEnter < numberB)
{
Console.WriteLine("You entered less number than computer& generated");
}
if (userEnter < numberA) {
Console.WriteLine("The number is outside the range between A ");
}
if (userEnter > numberB)
{
Console.WriteLine("The number is outside the range between B ");
}
& } while (userEnter != continuerandomnumber);
& Console.WriteLine("You entered true number");
& Console.ReadLine();
}
else {
& Console.WriteLine("B must be bigger than A ");
& EnterNumber();
}
}catch(Exception){
Console.WriteLine("B must be bigger than A ");
Console.ReadLine();
}
& }
& static void Main(string[] args)
& {

EnterNumber();
& }
}
}

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