Write a C# program to allow a user to guess a number( from 1 to 6) that will be randomly generated by computer.
The user is asked to input his/her number. Then the number will be compared with the random number. See the example below:
Enter your number: 2
You lost.
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
Random rand = new Random();
Console.Write("Enter your number: ");
int yourNumber=int.Parse(Console.ReadLine());
if (yourNumber == rand.Next(1, 7))
{
Console.WriteLine("You win.");
}
else {
Console.WriteLine("You lost.");
}
Console.ReadLine();
}
}
}
Comments
Leave a comment