Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program - Lottery Checker You're going to write a c++ program that models the Littleton City Lotto (not a real Lotto game). The program is

Program - Lottery Checker

You're going to write a c++ program that models the Littleton City Lotto (not a real Lotto game). The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly.

The rules for lotto work as follows:

1. Select 7 numbers between 1 and 40

2. Twice every week 7 numbers are drawn at random

3. If a player matches all 7 numbers they win a million dollar prize

4. If a player matches 6 numbers they win $100,000

5. If a player matches 5 numbers they win $5,000

6. If a player matches 4 numbers they win $100.

7. If a player matches 3 numbers they win a free ticket.

Your program should work as follows. (Note I have listed some functions you need to include in your program - you may include other functions if you would like and they make your program more readable/efficient).

Step 1:

Create an array named UserTicket to hold each of the user's lotto number selections.

Create an array named WinningNums to hold the winning lotto numbers.

Step 2:

Display the following menu:

LITTLETON CITY LOTTO MODEL:

---------------------------

1) Play Lotto

q) Quit Program

Please make a selection:

-If the selection is 1:

a. First ask the user their name and store it in an appropriate variable.

b. Next, call a function named getLottoPicks that asks the user to enter their 7 lotto number picks (selections) for the week. Each of the user's lotto picks should be stored in the UserTicket array. The lotto does NOT have duplicate numbers in it. Find a way to not allow duplicate numbers to be picked by the user. You may want to create another function called NoDuplicates that checks to see if the user's selection is already in the UserTicket array. If the user enters a number already in the array, ask them to enter another number until they enter one that is not a duplicate. This means the UserTicket array should contain no duplicate numbers.

c. Next, call a function named GenWinNums that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the WinningNums array (so you are going to fill the WinningNums array with random numbers between 1 and 40). Do not allow this function to generate duplicate winning numbers (if you design your NoDuplicates function above well you should be able to re-use it to check for duplicates in the WinningNums array).

Hint: there are two ways to avoid having duplicate numbers in an array. Most of you will need to use the first method. The first method is to check the array after each number is generated or entered to make sure that number is not already in the array. If the number generated/entered is already in the array a new number should be generated/entered. The second method involves sorting and checking that the numbers next to each other in the array after the sort are not the same - if you have taken CSIS 130 and know how to sort an array you can use this method.

d. The next step is to check the user's lotto ticket (represented by the UserTicket array) to see if they have won any prizes in the Lotto game. Check each number the UserTicket array to see if that number is in the WinningNums array and count how many numbers are matched.

Display a report similar to the following showing user's lotto results - the example output below assumes the user entered a name of "Julie" when the program started.

In the "Winnings" section of the report

Display: JACKPOT - 1 MILLION if all 7 numbers were correct

Display: GREAT! - $100,000 if 6 numbers were correct

Display: LUCKY YOU! - $5,000 if 5 numbers were correct

Display: NOT BAD - $100 if 4 numbers were correct

Display: FREE TICKET if 3 numbers were correct

Display: SORRY NOTHING if 2 or less numbers were correct

JULIE'S LOTTO RESULTS

---------------------

WINNING TICKET NUMBERS: 35 03 01 15 10 25 22

JULIE'S TICKET : 33 15 02 06 21 20 19

RESULTS:

--------

Number Matches: 1

Winnings : SORRY NOTHING

-If the selection is q: Quit the program

-If the selection is not q and not 1: Display an invalid selection message

Allow the user to play lotto as many times as they would like.

View required output

Test Case 1

Standard Input
1ENTER JAMES JONESENTER 10ENTER 10ENTER 10ENTER 7ENTER 8ENTER 41ENTER 40ENTER 30ENTER 25ENTER 20ENTER q
LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: Please enter your name: Please enter your 7 lotto number picks between 1 and 40. selection #1: selection #2: You already picked this number. Please enter a different number: You already picked this number. Please enter a different number: selection #3: selection #4: The number must be between 1 and 40. Please try again: selection #5: selection #6: selection #7: JAMES JONES'S LOTTO RESULTS ---------------------- WINNING TICKET NUMBERS : 22 27 21 34 32 06 28 JAMES JONES'S TICKET : 10 07 08 40 30 25 20 RESULTS : --------- Number Matches: 0 Winnings : SORRY NOTHING LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: You have chosen to quit the program. Thank you for using! Press any key to continue . . . 

Test Case 2

Standard Input
2ENTER tENTER 1ENTER ALICE GREENENTER -1ENTER 1ENTER 2ENTER 1ENTER 1ENTER 2ENTER 3ENTER 1ENTER 4ENTER 3ENTER 5ENTER 4ENTER 6ENTER 7ENTER q
LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: Invalid selection. Please try again. LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: Invalid selection. Please try again. LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: Please enter your name: Please enter your 7 lotto number picks between 1 and 40. selection #1: The number must be between 1 and 40. Please try again: selection #2: selection #3: You already picked this number. Please enter a different number: You already picked this number. Please enter a different number: You already picked this number. Please enter a different number: selection #4: You already picked this number. Please enter a different number: selection #5: You already picked this number. Please enter a different number: selection #6: You already picked this number. Please enter a different number: selection #7: ALICE GREEN'S LOTTO RESULTS ---------------------- WINNING TICKET NUMBERS : 26 15 05 17 27 12 20 ALICE GREEN'S TICKET : 01 02 03 04 05 06 07 RESULTS : --------- Number Matches: 1 Winnings : SORRY NOTHING LITTLETON CITY LOTTO MODEL: --------------------------- 1) Play Lotto q) Quit Program Please make a selection: You have chosen to quit the program. Thank you for using! Press any key to continue . . . 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions