Answer to Question #261112 in C# for Kiyemba Marvin

Question #261112
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.




1
Expert's answer
2021-11-04T16:26:12-0400
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();
        }




    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS