input three numbers if first number is greater than second invoke the swap function to swap first and second numbers if first is greater than third invoke the swap function to swap first and third numbers if second is greater than third invoke the swap function to swap second and third numbers output three sorted numbers
Lucky Five. In this assignment you are to code a program that selects 10 random non-repeating positive numbers, inputs 5 numbers from the user and checks the input with the 10 lottery numbers. The lottery numbers range from 0 to 99. The user wins if at least one input number matches the lottery numbers.
Study displaying arrays in functions described here. As you program your project, demonstrate to the lab instructor displaying an array passed to a function. Create a project titled Lab6_LuckyFive. Declare an array chosen of 10 integer elements.
Define the following functions:
Hint: Array elements are assigned
Passing an array as a parameter and its initialization is
done similar to the code in this program.
Hint: Looking for the match is similar to looking for the
minimum number in this program.
Hint: Use srand(), rand()
and time() functions that we studied earlier to generate
appropriate random numbers from 0 to 99 and fill the array. Before the
selected number is entered into the array chosen, 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 0
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
add the newly selected element to the array
increment the number of selected elements
Hint: Outputting the array can be done similar to
echoing it in this program.
The pseudocode your function main() should be as follows:
main(){ declare array and other variables assign(...) // fill array with -1 draw(...) // select 10 non-repeating random numbers iterate five times entry(...) // get user input use check () to compare user input against lottery numbers if won state and quit printOut(...) // outputs selected 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 result in a poor grade. Likewise, processing each user entry outside a loop is inefficient.
Note 2: For your project, 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 poor style. It should be avoided.
Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository. Do not forget to verify your submission on the web.