I am unable to get the same output, The powerball number has to be align with the ticket number as well as the drawing along with the powerball random number as shown on the images. Kindey, would you please test all my code? Thank you.   // Lotto Program #include #include #include #include using namespace std; // Functions declaration void printMenu(); int getSelect(int&); bool isUnique(int[], int, int); void printArray(int[], int); void selection2_output(int ticket[], int); //creating a fixed winner drawing  int drawing[] = { 56,34,1,8,12 }; 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"; } //for selection1 output void selection1_output() {     //random 5 number generation     int r[5];     for (int i = 0; i < 5; i++)     {         r[i] = 1 + (rand() % 69);     }     //Powerball generation               cout << setw(2) << left << "Player's Ticket:   ";     for (int i = 0; i < 5; i++)     {         cout << r[i] << " ";              }     int pw[1];     for (int i = 0; i < 1; i++)     {         pw[i] = 1 + (rand() % 26);     }     cout << "   ";     for (int i = 0; i < 1; i++)     {         cout<< setw(5) << right << pw[i];     }     //cout << setw(3) << right << pw[i];     //cout << "\n";     cout << setw(2) << right << "\nDrawing:           " ;     for (int i = 0; i < 5; i++)     {         cout << drawing[i] << " " ;     }     for (int i = 0; i < 1; i++)     {         pw[i] = 1 + (rand() % 26);     }     cout << "   ";     for (int i = 0; i < 1; i++)     {         cout << setw(6) << right << pw[i];     }     //comparing to check the number of common numbers     int same = 0;     for (int i = 0; i < 5; i++)     {         for (int j = 0; j < 5; j++)         {             if (r[j] == drawing[i])                 same++;         }     }     //if all numbers are common its a winner     if (same == 5)         cout << "\nYou Won the grand prize\n";     else         cout << "\nBetter luck next time!\n"; } //for selection2 void selection2_output(int ticket[]) {          cout << "Drawings :     ";     for (int i = 0; i < 5; i++)     {         cout << setw(4) << right << drawing[i] << " ";     }     int same = 0;     //comparing to check the number of common numbers     for (int i = 0; i < 5; i++)     {         for (int j = 0; j < 5; j++)         {             if (ticket[j] == drawing[i])                 same++;         }     }          //if all numbers are common its a winner     if (same == 5)         cout << "\nYou Won the grand prize\n";     else         cout << "\nBetter luck next time\n"; } // getSelection function int getSelect(int& sel) {     int count = 0;     int ticket[5];     //creating a fixed      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 == 1)         {             selection1_output();             break;         }         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);             int pwball = 0;             for (int i = 0; i < 1; i++)             {                 while (pwball < 26)                 {                     cout << "\n";                     cout << "Enter the powerball number (1 - 26): ";                     cin >> pwball;                     break;                 }             }             cout << "Player Ticket: ",                 printArray(ticket, count),                cout << pwball;                                       // powerball                        selection2_output(ticket);             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 << setw(4) << right << ticket[i] << " ";     }     cout << endl; }

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter8: Working With Advanced Functions
Section: Chapter Questions
Problem 2.8CP
icon
Related questions
Question

I am unable to get the same output, The powerball number has to be align with the ticket number as well as the drawing along with the powerball random number as shown on the images.

Kindey, would you please test all my code?

Thank you.

 

// Lotto Program
#include <ctime>
#include<iomanip>
#include <cstdlib>
#include<iostream>
using namespace std;

// Functions declaration

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

//creating a fixed winner drawing 
int drawing[] = { 56,34,1,8,12 };


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";
}

//for selection1 output
void selection1_output()
{
    //random 5 number generation
    int r[5];
    for (int i = 0; i < 5; i++)
    {
        r[i] = 1 + (rand() % 69);
    }
    //Powerball generation
    
    

    cout << setw(2) << left << "Player's Ticket:   ";
    for (int i = 0; i < 5; i++)
    {
        cout << r[i] << " ";
        
    }
    int pw[1];


    for (int i = 0; i < 1; i++)
    {
        pw[i] = 1 + (rand() % 26);

    }
    cout << "   ";
    for (int i = 0; i < 1; i++)
    {
        cout<< setw(5) << right << pw[i];
    }

    //cout << setw(3) << right << pw[i];
    //cout << "\n";

    cout << setw(2) << right << "\nDrawing:           " ;
    for (int i = 0; i < 5; i++)
    {
        cout << drawing[i] << " " ;
    }

    for (int i = 0; i < 1; i++)
    {
        pw[i] = 1 + (rand() % 26);

    }
    cout << "   ";
    for (int i = 0; i < 1; i++)
    {
        cout << setw(6) << right << pw[i];
    }

    //comparing to check the number of common numbers
    int same = 0;
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (r[j] == drawing[i])
                same++;
        }
    }

    //if all numbers are common its a winner
    if (same == 5)
        cout << "\nYou Won the grand prize\n";
    else
        cout << "\nBetter luck next time!\n";
}

//for selection2
void selection2_output(int ticket[])
{

    


    cout << "Drawings :     ";
    for (int i = 0; i < 5; i++)
    {
        cout << setw(4) << right << drawing[i] << " ";
    }

    int same = 0;
    //comparing to check the number of common numbers
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (ticket[j] == drawing[i])
                same++;
        }
    }

    
    //if all numbers are common its a winner
    if (same == 5)
        cout << "\nYou Won the grand prize\n";
    else
        cout << "\nBetter luck next time\n";

}

// getSelection function

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

    //creating a fixed 

    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 == 1)
        {
            selection1_output();
            break;
        }

        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);
            int pwball = 0;
            for (int i = 0; i < 1; i++)
            {
                while (pwball < 26)
                {
                    cout << "\n";
                    cout << "Enter the powerball number (1 - 26): ";

                    cin >> pwball;
                    break;
                }
            }
            cout << "Player Ticket: ",
                printArray(ticket, count),
               cout << pwball;
            
            
            // powerball

           
           selection2_output(ticket);
            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 << setw(4) << right << ticket[i] << " ";
    }
    cout << endl;
}

Welcome to the Lottery
1. Quick Pick
2. Pick Numbers
3. Exit
Selection: 2
Enter a unique number (1 - 69):99
Try again.
Enter a unique number (169):23
Enter a unique number (1 - 69):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 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
24
9
Transcribed Image Text:Welcome to the Lottery 1. Quick Pick 2. Pick Numbers 3. Exit Selection: 2 Enter a unique number (1 - 69):99 Try again. Enter a unique number (169):23 Enter a unique number (1 - 69):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 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 24 9
Welcome to the Lottery
1. Quick Pick
2. Pick Numbers
3. Exit
Selection: 2
69):99
Enter a unique number (1
Try again.
69):23
Enter a unique number (1-
Enter a unique number (1 - 69):67
Enter a unique number (1 - 69):5
Enter a unique number (1 - 69):13
Enter a unique number (169):13
Try again.
69):24
Enter a unique number (1
Enter the powerball number (126): 66
Try again.
Enter the powerball number (1 - 26): 24
Player's Ticket: 23 67 5 13 24
Drawing:
15 16 5 12 27
Better luck next time!
-
1.
2.
3.
-
Welcome to the Lottery
Quick Pick
Pick Numbers
Exit
Selection: 3
Program ended with exit code: 0
24
9
Transcribed Image Text:Welcome to the Lottery 1. Quick Pick 2. Pick Numbers 3. Exit Selection: 2 69):99 Enter a unique number (1 Try again. 69):23 Enter a unique number (1- Enter a unique number (1 - 69):67 Enter a unique number (1 - 69):5 Enter a unique number (1 - 69):13 Enter a unique number (169):13 Try again. 69):24 Enter a unique number (1 Enter the powerball number (126): 66 Try again. Enter the powerball number (1 - 26): 24 Player's Ticket: 23 67 5 13 24 Drawing: 15 16 5 12 27 Better luck next time! - 1. 2. 3. - Welcome to the Lottery Quick Pick Pick Numbers Exit Selection: 3 Program ended with exit code: 0 24 9
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
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
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT