Step 1:Create an array named UserTicket to hold each of the user’s lotto number
ID: 3914974 • Letter: S
Question
Step 1:Create an array named UserTicket to hold each of the user’s lotto number selections.Create an array named WinningNums to hold the winning lotto numbers.Step 2:Display the following menu:LITTLETON CITY LOTTO MODEL:---------------------------1) Play Lottoq) Quit ProgramPlease 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 getLottoPicks 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 UserTicket 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 will create another function called NoDuplicates that checks to see if the user’s selection is already in the UserTicket 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 UserTicket array should contain no duplicate numbers.c. Next, call a function named GenWinNums that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the WinningNums array (so you are going to fill the WinningNums array with random numbers between 1 and 40). Do not allow this function to generate duplicate winning numbers. Use the NoDuplicates function to check for duplicates in the WinningNums array. Note: do NOT call the srand function in GenWinNums (the srand is done the main ONLY).d. The next step is to check the user’s lotto ticket (represented by the UserTicket array) to see if they have won any prizes in the Lotto game. Check each number the UserTicket array to see if that number is in the WinningNums array and count how many numbers are matched.
Explanation / Answer
Screenshot
---------------------------------------------------------
Program
//Header files for I/o
#include<iostream>
#include<string>
using namespace std;
//Function prototype
void menu();
void getLottoPick(int *userTicketArray);
bool noDuplicate(int arr[], int val);
void genWinNums(int *winningNums);
//main method
int main()
{
//variables for user choice ,looping and match count
int ch,counter=0,loop=1;
//Arrays to store game numbers
int userTicketArray[7],winningNums[7];
//Variable for user name
string name = "";
//Loop continues until 2 select
while (loop == 1) {
//Call menu function
menu();
//prompt user for their choice
cout << "Please make a selection:-";
cin >> ch;
//If choice not matched repeat until match
while (ch<1 || ch>2) {
menu();
cout << "Please make a selection:-";
cin >> ch;
}
//User choice execution
switch (ch) {
//Play lotto
case 1:
//Prompt user name
cin.ignore();
cout << "Please enter your name: ";
getline(cin, name);
//call user to enter number function
getLottoPick(userTicketArray);
//Generate random winning number function call
genWinNums(winningNums);
//Match two arrays to get how many lotto got
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if (userTicketArray[i] == winningNums[j]) {
counter++;
}
}
}
//Display details
cout << "Player name= " << name << " Match count= " << counter << endl;
break;
//Exit from play
case 2:
cout << "Good Bye!!!" << endl;
exit(0);
}
}
return 0;
}
//Function for menu display
void menu() {
cout << " LITTLETON CITY LOTTO MODEL ----------------------------" << endl;
cout << "1) Play Lottoq 2) Quit" << endl;
}
//Duplicate check function
bool noDuplicate(int arr[], int val) {
int size = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i < size; i++) {
if (arr[i] == val) {
return true;
}
}
return false;
}
//Get users selection
void getLottoPick(int *userTicketArray) {
int i = 0, num = 0;
bool val;
while (i < 7) {
cout << "Please enter a number between 1-40: ";
cin >> num;
val= noDuplicate(userTicketArray, num);
while (val==true) {
cout << "No duplicates allowed, enter another number!!" << endl;
cout << "Please enter a number between 1-40: ";
cin >> num;
val = noDuplicate(userTicketArray, num);
}
userTicketArray[i] = num;
i++;
}
}
//Generate random numbers for winarray
void genWinNums(int *winningNums) {
int num = 0, i = 0;
bool val;
while (i < 7) {
num = (rand() % 40) + 1;
val = noDuplicate(winningNums, num);
while (val==true) {
num = (rand() % 40) + 1;
val = noDuplicate(winningNums, num);
}
winningNums[i] = num;
i++;
}
}
------------------------------------------------------------------------------
Output
LITTLETON CITY LOTTO MODEL
----------------------------
1) Play Lottoq
2) Quit
Please make a selection:-1
Please enter your name: Harish Mannah
Please enter a number between 1-40: 25
Please enter a number between 1-40: 14
Please enter a number between 1-40: 31
Please enter a number between 1-40: 39
Please enter a number between 1-40: 2
Please enter a number between 1-40: 5
Please enter a number between 1-40: 10
Player name= Harish Mannah
Match count= 4
LITTLETON CITY LOTTO MODEL
----------------------------
1) Play Lottoq
2) Quit
Please make a selection:-2
Good Bye!!!
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.