Respuesta :
Answer:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Guessgame
{
class Program
{
static void Main(string[] args)
{
//declare variables
int random;
int guess;
int tries = 0;
int quit;
//Create an instance of Random class
Random rand = new Random();
// random number between 1 and 10
random = rand.Next(10);
Console.WriteLine("The Guess My Number Game program");
Console.WriteLine("Enter a guess between 1 and 10");
guess = Convert.ToInt32(Console.ReadLine());
while (true)
{
//increment the tries by one
tries++;
//Check if guess is greater than random number
if (guess > random)
{
//print message
Console.WriteLine("Too high, try again.");
Console.WriteLine("Enter a guess between 1 and 10");
//read guess
guess = Convert.ToInt32(Console.ReadLine());
}
if (guess < random)
{
//print message
Console.WriteLine("Too low, try again.");
Console.WriteLine("Enter a guess between 1 and 10");
//read guess
guess = Convert.ToInt32(Console.ReadLine());
}
//Check if guess is random
if (guess == random)
{
//print message
Console.WriteLine("Congratualations!");
Console.WriteLine("Correct! You got it in " + tries + " guesses!");
//reset tries to zero
tries = 0;
Console.WriteLine("Enter a guess between 1 and 10");
//read guess from user
guess = Convert.ToInt32(Console.ReadLine());
// random number between 1 and 10
random = rand.Next(10);
}
}//end of while
quit = Convert.ToInt32(Console.ReadLine());
if(quit==0)
end;
}//end of main
}
}