Question

Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

Using C++ create a lotto program

Lottery

Design a program that simulates a lottery.

Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match.  No global variables can be used.

The program should contain separate functions for separate tasks such as input, processing, and output. The function used for input should allow the user to enter the 5 choices into the user array, validating each entry before storing it into the array. You should display the user’s choices as well as the winning lottery numbers correctly labeled. The function that does the processing should search the user array for each of the 5 numbers contained in the lottery array, incrementing a counter when they match, and returning the number of matches when complete. The function used for output should determine the winnings according to the following chart:

                1 match = $5

                2 matches = $15

                3 matches = $50

                4 matches = $100

                5 matches = $500

Note: Order selected does not matter when comparing user numbers to selected lottery numbers. It is assumed that the user will pick 5 different numbers.

Extra for Experts: Modify the program so that a 6th number is selected as the Powerball. To match the Powerball, your last choice must match the last choice of the winning numbers. The new winning schedule adds:

                Powerball = $10

                1 match + Powerball = $25

                2 matches + Powerball = $75

                3 matches + Powerball = $200

                4 matches + Powerball = $1000

                5 matches + Powerball = $50,000

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

using namespace std;

// this function generates the lottery array and takes input for user array
int fun_input(int lottery[],int user[])
{
    // generating the lottery array
    for (int i=0;i<5;i++)
    {
        int num = (rand() % (99 - 1 + 1)) + 1;
        //cout<>x;
        if(x>=1 && x<=99)
            user[i]=x;
        else
            return -1;
    }

    return 0;
}

// this function calculates the number of matches between lottery array and user array at corresponding indexes
int fun_process(int lottery[],int user[])
{
    int cnt=0;
    for(int i=0;i<5;i++)
        if(lottery[i]==user[i])
        cnt++;

    return cnt;
}

// this function outputs the prize money as per the matches
void fun_output(int match)
{
    if(match==1)
        cout<<"\nCongrats you won $5";
    else if(match==2)
        cout<<"\nCongrats you won $15";
    else if(match==3)
        cout<<"\nCongrats you won $50";
    else if(match==4)
        cout<<"\nCongrats you won $100";
    else if(match==5)
        cout<<"\nCongrats you won $500";
    else
        cout<<"\nSorry you didn't win\n";
}

int main()
{
    int lottery[5],user[5];
    int x=fun_input(lottery,user);
    
    // this indicates incorrect user input
     if(x==-1)
        cout<<"Incorrect user entry\n";
     else
     {
         int cnt=fun_process(lottery,user);
         fun_output(cnt);
     }

     return 0;
}

C:\Users\Rounak\3D Objects\rfes.exe Input the user entries: 1 23 45 67 33 Sorry you didnt win execution time : 8.073 s Pro

O C:\Users\Rounak\3D Objects\rfes.exe Input the user entries: 2 4 6 99 1 Sorry you didnt win execution time : 5.749 s Proc

C:\Users\Rounak\3D Objects\rfes.exe Input the user entries: 1 3 5 66 100 Incorrect user entry Process returned 0 (0x0) Pres

PLEASE LIKE THE SOLUTION :))

IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT

Add a comment
Know the answer?
Add Answer to:
Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...
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
  • 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...

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • 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 C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery...

    Need help with assignment This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers). More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the...

  • COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning...

    COP2221 - Intermediate C++ Programming Module #6 Assignment One 20 points This assignment refers to Learning Outcome #2: Create and utilize arrays to store lists of related data Programming Problem You have been hired to create a C++ program to simulate the lottery. Your program allows users to see how often their lottery number choices match a randomly generated set of numbers used to pick lottery winners. The company, "How Lucky Are You?, Inc." wants a modular, professional and user-friendly...

  • Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do resear...

    I HAVE A PROBLE WITH THIS JAVA PROBLEM CAN ANYONE HELP ME PLEASE. Exercise 2 Write a program that simulates the Texas Powerball lottery. You will have to do research to find out how many numbers are drawn, and what the range(s) of the numbers are. For this exercise you need to create a class called "Powerbali", which exposes a public function called play'. This function accepts several parameters , which represent the individual numbers the player wants to play....

  • Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have...

    Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have the program to randomly create a 3 digit lottery number. Have the user enter the number they will be playing and the results: (DO NOT USE ARRAYS or STRINGS) -If the user input matches the lottery number in the exact order, the award is $5Million. -If all the digits in the user input match all the digits in the lottery number, the award is...

  • 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...

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