Question

Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prev...

Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic

will allow the player to:

1)

Pick any 6 integer numbers from 1 - 70. Your logic should prevent the player

from selecting a value LESS than 1 or greater than 70. The logic should

prevent the player from selecting the SAME number (i.e. they cannot have

two or more of their selections be the SAME number).

2)

Display the players' 6 number selections on the CRT screen.

3)

Use the built in

rand

function to draw 6 numbers. This is the simulated

"balls" being picked by LOTTO (i.e.

ball = rand()% max_num + 1

;). You

will also need to set the seed for the random number algorithm:

srand( (unsigned)time( NULL ) );

4)

Determine the number of "matches" (those numbers that the player picked

that matches those that LOTTO drew).

5)

If you matched 0, 1 or 2 numbers, you win NO money (but print some

message such as "our schools WIN.").

6)

We’ll dispense with a Mega Number. You would probably wish to put the

logic in some sort of loop to ask the user whether they wish to play again

(clearing out the previous variables and arrays?)

If you match 3 numbers, you win $5.00.

If you match 4 numbers, you win $36.00.

If you match 5 numbers, you win $1,000.00 to $25,000.00 dollars (i.e.

random(25) + 1

).

If you match 6 numbers (NONE of them the BONUS) you win $1 million to $100 million

dollar (i.e.

random(100)

).

Tactical Hints:

1. Use a

pair

of one dimensional arrays of size 71. We ignore subscript 0, leaving 1 -

70. One array will "hold" the 6 numbers the player picked. The other array "holds"

the numbers LOTTO drew. Set all array location values of both arrays to 0. Set the

VALUE of one array’s location index location to 1 if the player selected the number

(i.e. they picked 2, therefore ARRAY subscript index location 2 has value 1). Set the

other array's location's value to 1 if LOTTO drew that number.

2. Compare both arrays to determine if a match occurred. If the same subscript location

on both arrays holds a 1, a match occurred. Use

for

loops to search through the

arrays.

3. Use a

switch

statement to determine the prize won based on the number of matches.

The number of matches is an integer.

This is an exercise in logic.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the code in C

Comments given so that you understand which code does what.

=================================================================================

#include<time.h>

#include<stdio.h>

#include<stdlib.h>

# define max_num 70

int main(){

               

                int userNumbers[71];

                int randomNumbers[71];

                for(int i=0; i<71;i++){

                                userNumbers[i]=0;

                                randomNumbers[i]=0;

                }

                int userNumber=0;

                printf("WELCOME TO CALIFORNIA SUPPER LOTTO\n");

                printf("===================================\n");

               

                // below code takes in user numbers

                for(int number=1;number<=6;number++){

                                printf("\nEnter your number %d: ",number);

                                scanf("%d",&userNumber);

                                if(userNumber<1 || userNumber>70){

                                                printf("\nYou need to enter a number between 1 and 70 (both inclusive). Please try again");

                                                number--;

                                }else if(userNumbers[userNumber]==1) {

                                                printf("\nYou already choose this number. Please enter a different number.");

                                                number--;

                                }else{

                                                userNumbers[userNumber]=1;

                                }

                }

                // seed the random number

                srand((unsigned)time(NULL));

                // generate 6 different numbers

                for(int number=1;number<=6;number++){

                                int ball = rand()%max_num+1;

                                if(randomNumbers[ball]==1){

                                                number--;

                                }else{

                                                randomNumbers[ball]=1;

                                }

                }

                // find how many were exact matches

                int matches=0;

                for(int number=1;number<=max_num;number++){

                                if(userNumbers[number]==1 && randomNumbers[number]==1){

                                                matches+=1;

                                }

                }

               

                // print the random numbers

                printf("\nHERE ARE THE GENERATED NUMBERS");

                printf("\n------------------------------\n");

                for(int number=1;number<=max_num;number++){

                                if(randomNumbers[number]==1){

                                                printf("%d ",number);

                                }

                }

               

                // display the result

                switch (matches){

                                case 0:case 1:case 2:

                                                printf("\nYOU WIN NO MONEY!!\n");

                                                break;

                                                case 3:

                                                                printf("\nCONGRATULATIONS! YOU WIN $5.00!!\n");

                                                break;

                                                case 4:

                                                                printf("\nCONGRATULATIONS! YOU WIN $36.00!!\n");

                                                break;

                                                case 5:

                                                                printf("\nCONGRATULATIONS! YOU WIN $1,000 to $25,000 !!\n");

                                                break;

                                                case 6:

                                                                printf("\nCONGRATULATIONS! YOU WIN $ 1 MILLION TO $ 100 MILLION!!\n");

                }

}

=================================================================================

Add a comment
Know the answer?
Add Answer to:
Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prev...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...

    java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly. The rules for lotto work as follows: Select 7...

  • Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an...

    Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique.  The Lottery class...

  • In C... Write a program to simulate a pick-5 lottery game. Your program must generate and...

    In C... Write a program to simulate a pick-5 lottery game. Your program must generate and store 5 distinct random numbers between 1 and 9 (inclusive) in an array. The program prompts the user for: an integer random seed five distinct integers between 1 and 9 (which are stored in another array) The program then compares the two arrays to determine if they are identical. If the two arrays are identical, then the user wins the game. otherwise the program...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • In Java, Using arrays. You are going to write a program that will play a solitaire...

    In Java, Using arrays. You are going to write a program that will play a solitaire (one-player) game of Mancala (Links to an external site.) (Links to an external site.). The game of mancala consists of stones that are moved through various buckets towards a goal. In this version of mancala, the user will be able to choose a number of buckets and a number of stones with which to set up the game. The buckets will be created by...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • In this project, you will write a complete program that allows the user to play a...

    In this project, you will write a complete program that allows the user to play a game of Mastermind against the computer. A Mastermind game has the following steps: 1. The codebreaker is prompted to enter two integers: the code length n, and the range of digits m. 2. The codemaker selects a code: a random sequence of n digits, each of which is in the range [0,m-1]. 3. The codebreaker is prompted to enter a guess, an n-digit sequence....

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT