Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Our objective in this lab exercise is to write a C program that simulates a lottery game using arrays. This program will prompt the user
Our objective in this lab exercise is to write a C program that simulates a lottery game using arrays. This program will prompt the user to enter 5 integer values between 0 and 9 and store them inside an array of integers. The program will then compare the user- provided array to a randomly generated array of integers, representing the winning combination. If the user-provided values match the winning numbers, the program will declare that the user has won the lottery. Otherwise, the program will ask the user to play again. To generate a random integer between 0 and 9, we can use the srand() and rand() functions from the library, in conjunction with the time() function from the library. As an example, the following code snippet will generate a random integer between 0 and 9 and store the result in an integer variable named intVar. #include #include #include void main() { srand(time()); int intVar; intVar = rand() % 10; printf("%d", intVar); } To compare the user-provided array of integers with the randomly generated one, your program must define and implement a function named CheckNumbers(). This function must accept two int arrays, and return a Boolean value (i.e., true or false). If all elements of the two input arrays are equal, this function will return true, otherwise it will return false. The Boolean data type is available from the library. Requirements Your lab3.c" program must satisfy the following requirements for full credit. 1. It must be named lab3.c and compile and execute without error. No other file extensions are acceptable. 2. It must use the scanf() function to prompt the user to provide an array of 5 integers between 0 and 9. The user-provided values must be stored in an int array of length 5 named numbers using a for-loop. 3. It must generate 5 random integers using the rand() function and store them in an int array of length 5 named winner inside a for-loop. 4. It must define and implement a function named CheckNumbers() that accepts two int arrays as input parameters and returns true if all elements of both arrays are equal. Otherwise, this function must return false. 5. Function CheckNumbers() must not make any calls to the printf() function. 6. The main() function must call function CheckNumbers() to conduct the comparison between the user-provided array numbers and the randomly generated array winner. If the returned value is equal to true, the main() function must use the printf() function to let the user know they have won the lottery. Otherwise, the main() function must use the printf() function to inform the user of the outcome. > Enter 5 integers between 0 and 9: 9 5 7 2 > The winning numbers were: 3, 4, 9, 2, 4 > Sorry, please try again. > Enter 5 integers between 0 and 9: 1 7 4 0 9 > The winning numbers were: 1, 7, 4, 0, 9 > You won
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started