A basic console-based Number Guessing Game created using C# in Visual Studio 2019. Git repository can be found here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NumberGuessingGame
{
class Program
{
static void Main(string[] args)
{
// Random class to generate a random number between the given range
Random random = new Random();
int winNum = random.Next(0, 100);
bool win = false;
do
{
Console.WriteLine("Choose a number between 0 and 100: ");
String s = Console.ReadLine();
int i = int.Parse(s);
if (i > winNum)
{
Console.WriteLine("Too High!! Guess a lower number...");
}
else if (i < winNum)
{
Console.WriteLine("Too Low!! Guess a higher number...");
}
else if (i == winNum)
{
Console.WriteLine("We all get there at the end, You Won!");
win = true;
}
} while (win == false);
Console.WriteLine("Thank you for playing!");
Console.WriteLine("Press any key to exit...");
Console.ReadKey(true);
}
}
}