Question

In: Computer Science

Using c# programming language Write a program that mimics a lottery game. Have the user enter...

Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with $25.

Solutions

Expert Solution

Solution:

Code:

Output:

Copyable Code:

using System;

//Main class

class MainClass {

//Main method

public static void Main (string[] args) {

//Declaration of variables

int number1,number2,number3;

int rand1,rand2,rand3;

int amount =25;

int i=1;

//Loop

do

{

//Get values

Console.WriteLine ("Enter 3 numbers between 1 and 10:");

Console.WriteLine("Enter the value of number1:");

number1=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the value of number2:");

number2=Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Enter the value of number3:");

number3=Convert.ToInt32(Console.ReadLine());

//Validation

if(number1>10 || number1<1)

{

Console.WriteLine("Renter the value of number1:");

number1=Convert.ToInt32(Console.ReadLine());

}

if(number2>10 || number2<1)

{

Console.WriteLine("Renter the value of number2:");

number2=Convert.ToInt32(Console.ReadLine());

}

if(number2>10 || number2<1)

{

Console.WriteLine("Renter the value of number1:");

number1=Convert.ToInt32(Console.ReadLine());

}

//Generate random values

Random r=new Random();

rand1=r.Next(1,10);

rand2=r.Next(1,10);

rand3=r.Next(1,10);

//Check with lottory values

if(number1==rand1 && number2==rand2 && number3==rand3)

{

Console.WriteLine ("Congrats!!Won on the lottery");

Console.WriteLine("Got $10");

amount=amount+10;

}

else if((number1==rand1 && number2==rand2)||(number2==rand2 && number3==rand3)||(number3==rand3 && number1==rand1))

{

Console.WriteLine("Got $3");

amount=amount+3;

}

else{

Console.WriteLine("You lose the game");

amount=amount-5;

}

i=i+1;

}while(i<=5);

Console.WriteLine("Your final amount is:"+amount);

}

}


Related Solutions

Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol,...
Write a program in C that lets the user enter a message using SMS Language(e.g. lol, omg, omw etc.), then translates it into English (e.g. laughing out loud, oh my god, on my way etc.). Also provide a mechanism to translate text written in English into SMS Language. needs to be able to translate at least 10 sms words
C programming. Write a program that prompts the user to enter a 6x6 array with 0...
C programming. Write a program that prompts the user to enter a 6x6 array with 0 and 1, displays the matrix, and checks if every row and every column have the even number of 1’s.
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Using C++ Write a program to ask user to enter a password and validity the password....
Using C++ Write a program to ask user to enter a password and validity the password. The password should be 8 – 20 characters long (8 is included and 20 is included), it should contain at least one uppercase letter and one lower case letter. The password should contain at least one digit, and at least one symbol other than alphabets or numbers. Most importantly, the password may not contain any white space. Functions: You will need at least the...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT