Write a program that simulates the Powerball lottery. In Powerball, a ticket is comprised of 5 numbers be

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Lotto Program C++
Write a program that simulates the Powerball lottery. In Powerball, a ticket is comprised of 5 numbers between 1 and 69 that must be unique, and a Powerball number between 1 and 26. The Powerball does not have to be unique. 

Hint: You can use an array to represent the 5 unique numbers between 1 and 69, and an integer variable to represent the powerball.

The program asks the player if they'd like to select numbers or do a 'quickpick', where the numbers are randomly generated for them. If they opt to select numbers, prompt them to type the numbers in and validate that they are unique (except the powerball), and in the correct range.

The program then generates a 'drawing' of 5 unique numbers and a Powerball, and checks it against the user's lotto ticket. It assigns winnings accordingly. Because it is so rare to win the lottery, I suggest hard coding or printing values to when testing the part of the program that assigns winnings.

Enter a unique number (169):24
Enter the powerball number (126): 66
Try again.
Enter the powerball number (126): 24
Player's Ticket: 23 67 5 13 24
Drawing:
15
16 5 12 27
Better luck next time!
Welcome to the Lottery
1. Quick Pick
2. Pick Numbers
3. Exit
Selection: 3
Program ended with exit code: 0
ticket [0] = 1;
ticket [1] = 2;
ticket [2] = 3;
ticket [3] = 4;
ticket [4] = 5;
Arun of the program that shows the input validation and that the program loops until the user chooses to exit.
Unfortunately, I did not win.
drawing[0] = 5;
drawing [1] = 4;
drawing [2] = 2;
drawing [3] = 1;
drawing [4] = 3;
powerball2 = powerball1 = 13;
Then, to test my win logic I hard coded my drawing and ticket values:
Player's Ticket: 1
Drawing:
5
You won the Grand Prize
The progra
24
32
41
1 23
5 4
5
3
32
24
n works when I win the grand prize. I changed a value in the player's ticket:
4
1
9
Player's Ticket:
Drawing:
You won 50,000$
50,000 is awarded. After testing the different combinations, I can be confident it works.
53
13
13
13
13
Transcribed Image Text:Enter a unique number (169):24 Enter the powerball number (126): 66 Try again. Enter the powerball number (126): 24 Player's Ticket: 23 67 5 13 24 Drawing: 15 16 5 12 27 Better luck next time! Welcome to the Lottery 1. Quick Pick 2. Pick Numbers 3. Exit Selection: 3 Program ended with exit code: 0 ticket [0] = 1; ticket [1] = 2; ticket [2] = 3; ticket [3] = 4; ticket [4] = 5; Arun of the program that shows the input validation and that the program loops until the user chooses to exit. Unfortunately, I did not win. drawing[0] = 5; drawing [1] = 4; drawing [2] = 2; drawing [3] = 1; drawing [4] = 3; powerball2 = powerball1 = 13; Then, to test my win logic I hard coded my drawing and ticket values: Player's Ticket: 1 Drawing: 5 You won the Grand Prize The progra 24 32 41 1 23 5 4 5 3 32 24 n works when I win the grand prize. I changed a value in the player's ticket: 4 1 9 Player's Ticket: Drawing: You won 50,000$ 50,000 is awarded. After testing the different combinations, I can be confident it works. 53 13 13 13 13
BALL
MATCH
+BALL
+BALL
BALL
1.
2.
3.
+BALL
+BALL
1.
2.
3. Exit
Selection: 1
Quick Pick
Pick Numbers
PRIZE
Grand Prize
$1 Million
$50,000
$100
$100
$7
$7
$4
$4
Welcome to the Lottery
Sample Output
Player's Ticket: 69 31 25 39
Drawing:
Better luck next time!
16
12 24 3 61 52
Welcome to the Lottery
Quick Pick
Pick Numbers
Exit
Selection: 2
Enter a unique number (1 - 69):99
Try again.
Enter a unique number (169):23
Enter a unique number (169):67
Enter a unique number (1 - 69):5
Enter a unique number (169):13
Enter a unique number (169):13
Try again.
Enter a unique number (1 - 69):24
Enter the powerball number (1-26): 66
Try anain
22
17
Transcribed Image Text:BALL MATCH +BALL +BALL BALL 1. 2. 3. +BALL +BALL 1. 2. 3. Exit Selection: 1 Quick Pick Pick Numbers PRIZE Grand Prize $1 Million $50,000 $100 $100 $7 $7 $4 $4 Welcome to the Lottery Sample Output Player's Ticket: 69 31 25 39 Drawing: Better luck next time! 16 12 24 3 61 52 Welcome to the Lottery Quick Pick Pick Numbers Exit Selection: 2 Enter a unique number (1 - 69):99 Try again. Enter a unique number (169):23 Enter a unique number (169):67 Enter a unique number (1 - 69):5 Enter a unique number (169):13 Enter a unique number (169):13 Try again. Enter a unique number (1 - 69):24 Enter the powerball number (1-26): 66 Try anain 22 17
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The firsrt picture that has on headther "MATCH and PRIZE" does not have to be coded, it is only an example of the poweball game.

The actual sample output it is bellow it.

 

Here is my code that need some review.

1. The input validation is working perfectly good.

2. I would like to complete the first selection as stated on the questionnaire output.

 

 

// Lotto Program

#include<iostream>
using namespace std;

// Functions declaration

void printMenu();
int getSelect(int &);
bool isUnique(int[], int, int);
void printArray(int [], int);

 

int main()
{
    int sel;

    printMenu();
    getSelect(sel);
    

    
    

    

    return 0;

}


// Functions implementation

// Menu function.

void printMenu()
{
    cout << "\tWelcome to the Lottery\t\n";
    cout << "  ---------------------------------\n";
    cout << "    1. Quick Pick\n";
    cout << "    2. Pick Numbers\n";
    cout << "    3. Exit\n";
}

// getSelection function

int getSelect(int &sel)
{
    int count = 0;
    int ticket[5];

    cout << " Selection: ";
    cin >> sel;

    // input validation.

    while (sel == 3)
    {
        cout << "Program ending..." << endl;
        return 0;
    }

    while (true)

    {
        while (sel <= 0 || sel > 3)
        {
            cout << " Please your selction must be between 1 and 3. Try again.\n";
            return 0;
        }


        //sel = getSelect(sel);

        while (sel == 2)
        {
            while (count < 5)
            {
                cout << "Enter a unique number (1 - 69): ";
                cin >> ticket[count];
                while (ticket[count] < 1 || ticket[count] > 69 || !isUnique(ticket, ticket[count], count))
                {
                    cout << "Try again.\n";
                    cout << "Enter a unique number (1 - 69): ";
                    cin >> ticket[count];
                    break;
                }
                count++;
                cout << endl;
                
            }
            
            isUnique(ticket, ticket[count], count);
            cout << "Player Ticket: ", printArray(ticket, count);
            break;
        }


        return sel;
    }
}

// isUnique Function
// This function determines if there is unique number 
// in the array.

bool isUnique(int ticket[], int n, int count)
{
    for (int i = 0; i < count; i++)
    {
        if (ticket[i] == n)
        {
            return false;

        }
    }
    return true;
}

// printArray Function.

void printArray(int ticket[], int count)
{
    for (int i = 0; i < count; i++)
    {
        cout << ticket[i] << " ";
    }
    cout << endl;
}

```plaintext
Welcome to the Lottery
----------------------
1. Quick Pick
2. Pick Numbers
3. Exit
Selection: 1

C:\Users\demusu\Documents\aims\fall_2022\Computer_science (c++)\assignments\Lotto_program\x64\Debug\Lotto_program.exe (process 6508) exited with code 0.
Press any key to close this window . . .
```

**Description:**

This image shows the output from a console application designed for a lottery program. The program offers three options for users:

1. **Quick Pick** - Automatically generates a set of lottery numbers.
2. **Pick Numbers** - Allows the user to manually choose their lottery numbers.
3. **Exit** - Closes the application.

In this particular instance, the user has selected option 1 ("Quick Pick").

The console also shows the file path for the program and indicates that the application terminated successfully, exiting with code 0. The user is prompted to press any key to close the window.
Transcribed Image Text:```plaintext Welcome to the Lottery ---------------------- 1. Quick Pick 2. Pick Numbers 3. Exit Selection: 1 C:\Users\demusu\Documents\aims\fall_2022\Computer_science (c++)\assignments\Lotto_program\x64\Debug\Lotto_program.exe (process 6508) exited with code 0. Press any key to close this window . . . ``` **Description:** This image shows the output from a console application designed for a lottery program. The program offers three options for users: 1. **Quick Pick** - Automatically generates a set of lottery numbers. 2. **Pick Numbers** - Allows the user to manually choose their lottery numbers. 3. **Exit** - Closes the application. In this particular instance, the user has selected option 1 ("Quick Pick"). The console also shows the file path for the program and indicates that the application terminated successfully, exiting with code 0. The user is prompted to press any key to close the window.
## Welcome to the Lottery Program

This interactive console application is designed for selecting lottery numbers. Users can choose between a quick pick option or manually enter their own numbers. Below is a step-by-step explanation of the process demonstrated in the program.

### Options:
1. **Quick Pick**
2. **Pick Numbers**
3. **Exit**

### User Interaction:
- **Selection Choice**: The user selects option `2` to manually pick numbers.
- **Enter Unique Numbers**: The user is prompted to enter five unique numbers within the range of 1 to 69. The numbers chosen in this session are:
  - 11
  - 33
  - 55
  - 5
  - 8

### Output:
- **Player Ticket**: Displays the selected numbers: `11 33 55 5 8`

### Debug Information:
- Execution path: The program runs from the file system path: `C:\Users\demusu\Documents\aims\fall_2022\Computer_science (c++)\assignments\Lotto_program\x64\Debug\Lotto_program.exe`
- **Exit Code**: Confirmation that the program executed successfully with an exit code of `0`.

### Note:
To close the application, the user is prompted to press any key.

This educational example is ideal for demonstrating basic console input/output operations and decision-making in C++.
Transcribed Image Text:## Welcome to the Lottery Program This interactive console application is designed for selecting lottery numbers. Users can choose between a quick pick option or manually enter their own numbers. Below is a step-by-step explanation of the process demonstrated in the program. ### Options: 1. **Quick Pick** 2. **Pick Numbers** 3. **Exit** ### User Interaction: - **Selection Choice**: The user selects option `2` to manually pick numbers. - **Enter Unique Numbers**: The user is prompted to enter five unique numbers within the range of 1 to 69. The numbers chosen in this session are: - 11 - 33 - 55 - 5 - 8 ### Output: - **Player Ticket**: Displays the selected numbers: `11 33 55 5 8` ### Debug Information: - Execution path: The program runs from the file system path: `C:\Users\demusu\Documents\aims\fall_2022\Computer_science (c++)\assignments\Lotto_program\x64\Debug\Lotto_program.exe` - **Exit Code**: Confirmation that the program executed successfully with an exit code of `0`. ### Note: To close the application, the user is prompted to press any key. This educational example is ideal for demonstrating basic console input/output operations and decision-making in C++.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education