Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Really confused with these lab 2. Lottery. In this assignment you are to code a program that selects 20 random non-repeating positive numbers (the lottery

Really confused with these lab image text in transcribed
2. Lottery. In this assignment you are to code a program that selects 20 random non-repeating positive numbers (the lottery numbers), takes a single input from the user and checks the input with the twenty lottery numbers. The lottery numbers range from 1 to 100. 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 20 integer elements. Define the following functions: o Define function assign)that takes array winst as a parameter and assigns 0 to each element of the array. Hint: Array elements are assigned 0, which is outside of lottery numbers range, to distinguish elements that have not been given lottery numbers yet Passing an array as a parameter and its initialization is done similar to the code in this progam o Define a predicate function checkthat takes a number and the array winst 1 as parameters and returns true if the number matches one 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 that check) is looking for is always positive. Hint: Looking for the match is similar to looking for the minimum number in this prongram o Define a function dra) that takes array wins as a parameter and fills it with 20 random integers whose values are from 1 to 100. The numbers should not repeat. Hint: Use srand(), rand) and time) functions that we studied earlier to generate appropriate random numbers from to 100 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 drawt) 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 randon number eall check) to see it this new random number is already in the a if the new random number is not in the array increment the number of seleceted elements add the newly selected elenent to the array o Define function entry that asks the user to enter a single number from 1 to 100 and returns this value. o Define function printout) that outputs the selected numbers and user input. Hint: Outputting the array can be done similar to echoing it in this program The pseudocode your function main) should be as follows: main)f declare array and other variables assign(.fill array with draw entry use checkto conpare user input against lottery numbers and output whether user won printout(.outputs selected lottery numbers // select 20 non-repeating random numbers // get user input

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions