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
Lottery. In this assignment you are to 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.
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_Lottery. Declare an array wins of 10 integer elements.
Define the following functions:
Hint: Array elements are initialized to
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 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
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 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 result in a poor grade.
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.