C++ Include comments with program Thank you! SAMPLE OUTPUT (example of how the o
ID: 3769219 • Letter: C
Question
C++
Include comments with program
Thank you!
SAMPLE OUTPUT (example of how the output should be)
in a process of creating a weekly lottery. Once a week, five distinct random integers betweenlto.40 (inclusive) are drawn. If a player guesses all of the numbers correctly, the player wins a certain amount. Write a program that does the following: a. Generates five distinct random numbers between 1 and 40 (inclusive) and stores them in an array b. Sorts the array containing the lottery numbers. c. Prompts the player to select five distinct integers between 1 and 40 (inclusive) and stores the numbers in an array. The player can select the numbers in any order, and the array containing the numbers need not be sorted. d. Determines whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers correctly, it outputs the message You win!" otherwise it outputs the message "You lose!" and outputs the lottery numbers. Your program should allow a player to play the game as many times as the player wants to play. Before each play, generate a new set of lottery ywanto play Before each play. generate a new set of lotery numbers.Explanation / Answer
#include <iostream>
#include <string>
#include<string>
#include<cctype>
#include <cstdlib>
#include <ctime>
using namespace std;
const int YOURNUM = 5;
const int WINGNUM = 5;
void getLottoPicks(int nums[],int size);
void GenWinNum(int nums [], int size);
int main()
{
char selection;
string name;
int UserTicket [YOURNUM];
int winningNums [WINGNUM];
int matching = 0;
/*srand ((unsigned int)time(NULL));*/
do
{
cout <<" LITTLETON CITY LOTTO MODEL:" <<endl
<<"---------------------------" <<endl
<<"1) Play Lotto" <<endl
<<"q) Quit Program" <<endl
<<"Please make a selection" <<endl;
cin >> selection;
cin.ignore();
while(selection != '1' && selection != 'q' && selection != 'Q')
{
cout <<" Invalid Selection" <<endl
<<"LITTLETON CITY LOTTO MODEL:" <<endl
<<"---------------------------" <<endl
<<"1) Play Lotto" <<endl
<<"q) Quit Program" <<endl
<<"Please make a selection" <<endl;
cin >> selection;
cin.ignore();
}
if(selection == '1')
{
cout <<"Please enter your name."<<endl;
getline(cin,name);
getLottoPicks(UserTicket,YOURNUM);
GenWinNum(UserTicket,YOURNUM);
for(int index = 0; index < YOURNUM; index++)
{
int temp = UserTicket[index];
for(int index = 0; index < WINGNUM; index++)
{
if(temp == winningNums[index])
{
matching++;
}
}
}
cout <<" " << name <<"'s Lotto Results" <<endl
<<"----------------------" <<endl
<<"Winning Ticket Numbers :";
for(int index = 0; index < WINGNUM; index++)
{
cout <<" " << winningNums[index];
}
cout <<" " <<name <<"'s Ticket :";
for(int index = 0; index < YOURNUM; index++)
{
cout <<" " << UserTicket[index];
}
cout << "RESULTS :" <<endl
<< "--------" <<endl
<< "Number Matches:" <<matching
<< "Winnings :";
if(matching <= 2)
{
cout <<"YOU LOSE"<<endl;
}
else if(matching == 3)
{
cout << "FREE TICKET"<<endl;
}
else if(matching == 4)
{
cout << "NOT BAD - $100"<<endl;
}
else
{
cout << "YOU WIN"<<endl;
}
}
}while(selection != 'q' && selection !='Q');
cout << "You have chosen to quit the program. Thank you for using!"<<endl;
system("pause");
return 0;
}
void getLottoPicks(int numbers[],int size)
{
int yourticket = numbers[size];
cout << "Please enter your 5 lotto number picks between 1 and 40: " << endl;
for (int i = 0; i < size; i++)
{
cout << "selection #" << i + 1 << endl;
cin >> numbers[i];
cin.ignore();
while (numbers[i] < 1 || numbers[i] > 40)
{
cout << "Please choose a number between 1 and 40: " << endl;
cin >> numbers[i];
}
for (int j = 0; j < i; j++)
{
while (numbers[i] == numbers[j])
{
cout << "You have already picked that number. Enter a different one: " << endl;
cin >> numbers[i];
cin.ignore();
}
}
}
}
void GenWinNum (int nums [], int size)
{
srand ((unsigned int)time(NULL));
int winning = rand () % 40 + 1;
for (int count = 0; count < size; count++)
{
nums[count] = winning;
for (int j = 0; j < count; j++)
{
while (nums[count] == nums[j])
{
nums[count] = winning;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.