using System;
using System.Collections.Generic;
using System.Text;
namespace GuessNumber
{
class GuessNumber
{
static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("Welcome to Guess a Word Program (0-100) with in 5 attempts.");
System.Random r = new Random();
int x = r.Next(100);
bool bGuessedCorrectly = false;
for (int i = 1; i <= 5; i++)
{
Console.Write("ATTEMPT " + i + ": Enter the your number: ");
int n = Convert.ToInt32(Console.ReadLine());
if (n == x)
{
Console.WriteLine("Congrats! You have guessed the number correctly");
bGuessedCorrectly = true;
break;
}
int diff = (int)(Math.Abs(x - n));
bool bMoveHigher = false;
if(x > n)
bMoveHigher = true;
if(diff >= 50)
{
if (bMoveHigher == false)
Console.WriteLine("Your guess is VERY HIGH");
else
Console.WriteLine("Your guess is VERY LOW");
}
else if (diff >= 30)
{
if (bMoveHigher == false)
Console.WriteLine("Your guess is HIGH");
else
Console.WriteLine("Your guess is LOW");
}
else if (diff >= 15)
{
if (bMoveHigher == false)
Console.WriteLine("Your guess is MODERATELY HIGH");
else
Console.WriteLine("Your guess is MODERATELY LOW");
}
else
{
if (bMoveHigher == false)
Console.WriteLine("Your guess is SOMEWHAT HIGH");
else
Console.WriteLine("Your guess is SOMEWHAT LOW");
}
}
if (bGuessedCorrectly == false)
{
Console.WriteLine("Unfortunately you did not guess it correctly. The correct number is: " + x);
}
Console.ReadLine();
}
}
}
Guess the Number
No comments:
Post a Comment