Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code a program that selects 10 random non-repeating positive numbers (the lottery numbers), takes a single input from the user and checks the input with

Code a program that selects 10 random non-repeating positive numbers (the lottery numbers), takes a single input from the user and checks the input with the ten lottery numbers. The user wins if her input matches one of the lottery numbers. Create a project titled Lottery. Declare an array wins of 10 integer elements. Define the following functions:

o Define function initialize() that takes array wins[] as a parameter and assigns -1 to each element of the array. Hint: Array elements are initialized to -1, which is outside of lottery numbers' range, to distinguish elements that have not been given lottery numbers yet.

o Define a function check() that takes a number and the array wins[] as parameters and returns true if is number matches on of the elements in the array, or false if none of the elements do. That is, in the function, you should write the code that iterates over the array looking for the number passed as the parameter. You may assume that the number check() is looking for is always positive.

o Define a function draw() that takes array wins as a parameter and fills it with 10 random integers whose values are from 0 to 99. The numbers should not repeat. Use srand(), rand() and time() functions to generate appropriate random numbers from 0 to 99 and fill the array. Before the selected number is entered into the array wins, call function check() to make sure that the new number is not already in the array. If it is already there, select another number. The pseudocode for your draw() function may be as follows: declare a variable "number of selected lottery numbers so far", initialize this variable to zero while (the_number_of_selected_elements is less than the array size) select a new random number call check() to see if this new random number is already in the array if the new random number is not in the array increment the number of selected elements add the newly selected element to the array

o Define function entry() that asks the user to enter a single number from 0 to 99 and returns this value.

o Define function printOut() that outputs the selected numbers and user input. Hint: echoing. The pseudocode your function main() should be as follows: main(){ declare array and other variables initialize(...) // fill array with -1 draw(...) // select 10 non-repeating random numbers entry(...) // get user input use check () to compare user input against lottery numbers and output whether user won printOut(...) // outputs seleced lottery numbers } Note: A program that processes each element of the array separately (i.e. accesses all 10 elements of the array for assignment or comparison outside a loop) is inefficient and will not be accepted. Note 2: For your homework assignment, you should either pass the array size (10) to the functions as a parameter or use a global constant to store it. Hard-coding the literal constant 10 in function definitions that receive the array as a parameter is NOT ACCEPTABLE.

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_2

Step: 3

blur-text-image_3

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago