Guessing game 3
using System;
namespace GuessingGame2
{
class Program
{
static void Main()
{
//Console.WriteLine(randomNumber);
int userNum;
int range = 51;
int gamesplayed = 0;
int counter = 0;
string reset = "";
Console.WriteLine("Range 1 to {0}---|", --range);
while (reset != "A")
{
Random randomGenerator = new Random();
int randomNumber = randomGenerator.Next(1, range);
do
{
Console.WriteLine("Guess the number|");
userNum = int.Parse(Console.ReadLine());
if (userNum < randomNumber)
Console.WriteLine("Your num is less|");
else if (userNum > randomNumber)
Console.WriteLine("Your num is high|");
else
Console.WriteLine("Your correct |");
counter++;
} while (userNum != randomNumber);
Console.WriteLine("Turns taken : {0} |\n-----------------", counter);
counter = 0;
Console.Write("Enter anything to start again :");
reset = Console.ReadLine();
gamesplayed++;
if (reset == "exit")
break;
}
Console.Write("Games played {0}", gamesplayed);
}
}
}
Comments
Post a Comment