19.3k views
3 votes
Write a program that simulates a lottery. the program should have an array of five integers named winning digits, with a randomly generated number in the range of 0 through 9 for each element in the array.

the program should ask the user to enter five digits and should store them in a second integer array named player.

the program must compare the corresponding elements in the two arrays and count how many digits match.

for example, the following shows the winningdigits array and the player array with sample numbers stored in each. there are two matching digits, elements 2 and 4.

the grand prize winner is determined by all 5 matching digits.

the program should use functions for the following processes (3):
a. random number generation for lottery
b. prompt for user data entry
c. match processing and winner determination

Submission should have:
- Screen shot of program running in Linux environment
- Contain proper indentation
- Comments (Blocks or Lines)
- Good Variables initializations
- Input Validation
- Output display with explanation

1 Answer

7 votes

Final answer:

The program simulates a lottery by generating random numbers, taking user input, and comparing it to the winning digits to determine if the user wins the grand prize.

Step-by-step explanation:

The requested program simulates a lottery in which the user tries to match five randomly generated digits for a chance to win a grand prize. The program contains three main functions: one for generating random numbers for each of the five winning digits, another for prompting the user to enter their chosen digits into the player array, and a third function for processing matches and determining if the user has won the grand prize. Proper input validation ensures that the user enters only valid integers, and comments are used throughout the program to explain the code's functionality.

Your chance of winning the grand prize in such a lottery game is extremely low, since each number has a 1 in 10 chance of being correct, and all five must be correct and in the right order. This example illustrates the use of probabilities in determining expected outcomes in games of chance.

User Frank Sposaro
by
8.6k points