In: Computer Science
Need this in C#
Write a simple lottery program which can do the following:
1. asks the user to provide an integer value from 1 to 5
2. generates one random integer number from 1 to 5
3. display “You lost $1” if the two numbers are different, and display “You won $5” otherwise.the program asks if the user wants to continue playing the lottery.
If yes, the program repeats steps 1-3. If no, the program terminates.
Program
using System;
class Lottery
{
//Main method
static void Main(string[] args)
{
Random
r = new Random();
string
fg = "y";
while(fg=="y"
|| fg=="Y")
{
//prompt
the user to provide an integer value from 1 to 5
Console.Write("Enter
an integer value from 1 to 5: ");
//read
the integer value
int
guess = int.Parse(Console.ReadLine());
//generates
one random integer number from 1 to 5
int
randnum= r.Next(1, 5);
if(guess
== randnum)
Console.WriteLine("You
won $5");
else
Console.WriteLine("You
lost $1");
Console.Write("Are
you wants to continue playing the lottery (y/n)? :");
fg
= Console.ReadLine();
}
}
}
Output
Solving your question and
helping you to well understand it is my focus. So if you face any
difficulties regarding this please let me know through the
comments. I will try my best to assist you. However if you are
satisfied with the answer please don't forget to give your
feedback. Your feedback is very precious to us, so don't give
negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid
plagiarism.
Thank you.