Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Imaginary City just began their city lotto. You must write a C++ program for the

ID: 3875732 • Letter: I

Question

Imaginary City just began their city lotto. You must write a C++ program for them. The program is going to allow the 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. Make sure the numbers are truly random not pseudo random.

The rules for lotto work as follows:

Select 7 numbers between 1 and 50
Twice every week 7 numbers are drawn at random
If a player matches all 7 numbers they win a 100,000
If a player matches 6 numbers they win $10,000
If a player matches 5 numbers they win $1,000
If a player matches 4 numbers they win $50.
If a player matches 3 numbers they win a scratcher.
The program should work as follows.

Step 1

Create an array named Lot to hold each of the user’s lotto number selections.

Create an array named Lotw to hold the winning lotto numbers.

Step 2

Display the following menu:

Imaginary City Gambling:

1) Play

e) Exit

Please make a selection:

If the selection is 1:

a. First ask the user their name and store it in an appropriate variable.

b. Next, call a function named lg that asks the user to enter their 7 lotto number picks (selections) for the week. Each of the user’s lotto picks should be stored in the Lot array. The lotto does NOT have duplicate numbers in it. Find a way to not allow duplicate numbers to be picked by the user. You may want to create another function called zerocopies that checks to see if the user’s selection is already in the Lot array. If the user enters a number already in the array, ask them to enter another number until they enter one that is not a duplicate. This means the Lot array should contain no duplicate numbers.

c. Next, call a function named Createw that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the Lotw array (so you are going to fill the Lotw array with random numbers between 1 and 50). Do not allow this function to generate duplicate winning numbers (if you design your zero copies function above well you should be able to re-use it to check for duplicates in the Lotw array). Also make sure that the randomly generated winning lotto numbers are actually random and not pseudo random.

Clue: There are two ways to avoid having duplicate numbers in an array. The first method is to check the array after each number is generated or entered to make sure that number is not already in the array. If the number generated/entered is already in the array a new number should be generated/entered. The second method involves sorting and checking that the numbers next to each other in the array after the sort are not the same.

d. The next step is to check the user’s lotto ticket (represented by the Lott array) to see if they have won any prizes in the Lotto game. Check each number the Lot array to see if that number is in the Lotw array and count how many numbers are matched.

Output

Display a report similar to the following showing user’s lotto results – the example output below assumes the user entered a name of “Alex” when the program started.

In the “Winnings” section of the report

Display: PHENOMENAL!!! - $100,000 if all 7 numbers were correct

Display: OUTSTANDING!!! - $10,000 if 6 numbers were correct

Display: AWESOME!!!! - $1,000 if 5 numbers were correct

Display: OK - $50 if 4 numbers were correct

Display: FREE SCRATCHER if 3 numbers were correct

Display: OUT OF LUCK if two or less numbers were correct

Sample Output:-

ALEX'S LOTTO RESULTS

WINNING NUMBERS: 35 03 01 15 10 25 22

ALEX’S TICKET: 33 15 02 06 21 20 19

RESULTS:

Matches: 1        

Winnings : OUT OF LUCK!

If the selection is e: Exit

If the selection is not e and not one: Display an invalid selection message

Allow the user to play lotto as many times as they would like.

Explanation / Answer

#include<iostream>

using namespace std;

bool ZeroCopies(int[],int,int);

void Createw(int[],int);

void lg(int[],int);

char selectOption(void);

int winCheck(int[],int[],int);

void result(int[],int[],int,int,string);

int main()

{

int TicketUser[7],NumWins[7],max=7;

int countuser=0,countwins=0,i,matches=0;

char option=1;

string name;

option=selectOption();

while(option!='e')

{

    cout<<"Enter your name:";

    getline(cin,name,' ');

    lg(TicketUser,max);

    Createw(NumWins,max);

    matches=winCheck(TicketUser,NumWins,max);

    result(TicketUser,NumWins,max,matches,name);

    option=selectOption();

}

return 0;

}

void result(int a[],int b[],int n,int m,string name)

{

int i;

cout<<name<<"'s LOTTO RESULT ****************** WINNING NUMBERS: ";

for(i=0;i<n;i++)

    cout<<b[i]<<" ";

cout<<" "<<name<<"'s TICKET: ";

for(i=0;i<n;i++)

    cout<<a[i]<<" ";

cout<<" RESULT: ****************** Matches: "<<m<<" Winnings:";

switch(m)

{

    case 7:     cout<<"PHENOMENAL!!! - $100,000";break;

    case 6:     cout<<"OUTSTANDING!!! -$10,000";break;

    case 5:     cout<<"AWESOME!!! -$1,000";break;

    case 4:     cout<<"OK -$50";break;

    case 3:     cout<<"FREE SCRATCHER";break;

    default:    cout<<"OUT OF LUCK";break;

}

cout<<endl<<endl;

int enter=cin.get();        

return;

}

          

int winCheck(int a[],int b[],int n)

{

int i,j,numEqual=0;

   for(i=0;i<n;i++)

      for(j=i;j<n;j++)

        if(a[i]==b[j])

        {

          numEqual++;

          cout<<i<<" "<<j<<" "<<a[i]<<""<<a[j]<<" "<<numEqual<<endl;

        }

return numEqual;

}

void Createw(int a[],int n)

{

int i;

bool copy=true;

for(i=0;i<n;i++)

{

    while(copy)

    {

      a[i]=rand()%40+1;

      copy=ZeroCopies(a,i,2);

    }

    copy=true;

}

}

void lg(int a[],int n)

{

int i;

bool copy=true;

for(i=0;i<n;i++)

{

    while(copy)

    {

      again: cout<<"Enter number (between 1 and 40)"<<i+1<<": ";

      cin>>a[i];

      if(a[i]<1||a[i]>40)

      {

        cout<<"number out of range ";

          goto again;        

      }

      copy=ZeroCopies(a,i,1);

    }

    copy=true;

}

return;

}

bool ZeroCopies(int a[],int n, int f)

{

int i,j;

bool copy=false;

if(n==0)

    return false;

for(i=0;i<=n-1;i++)

    if(a[n]==a[i])

    {

      copy=true;

      if(f==1)       

      {

        cout<<"DUPLICATE PICK of numbers:";

        for(j=0;j<n;j++)

          cout<<a[j]<<" ";

          cout<<endl;

      }

    }

return copy;

}

char selectOption()

{

bool correct=false;

char option,enter;

cout<<"Imaginary City Gambling: ";

cout<<"__________________________ ";

cout<<"1) Play e) Exit Please make a selection: ";

while(!correct)

{

    option=cin.get();

    enter=cin.get();        

     if(option=='1'||option=='e')

        return option;

      cout<<"Incorrect entry - try again ";

}

}

--------------------------------------------------------------------------------