1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rudiy27
3 years ago
6

You’re going to write a program that models the Littleton City Lotto (not a real Lotto game). The program is going to allow to u

ser 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.
Engineering
1 answer:
sveta [45]3 years ago
8 0

Answer:

Explanation:

// Include the required

// header files.

#include <iostream>

#include <cstdlib>

#include <iomanip>

#include <ctime>

#include <string>

// Use the

// standard namespace.

using namespace std;

// Define the function NoDuplicates(),

// to check whether a value is already

// present in an array or not.

int NoDuplicates(int arr[], int size, int val)

{

// Run the loop to

// traverse the array.

for(int i=0; i<size; i++)

{

// If the value is already present

// in the array, return 0.

if(arr[i] == val)

{

return 0;

}

}

// Otherwise, return 1.

return 1;

}

// Define the function getLottoPicks().

void getLottoPicks(int UserTicket[])

{

int currNum;

//

// Run the oop to get 7

// numbers from the user.

for(int i=0; i<7; i++)

{

// Prompt the user

// to enter the number.

cout << "Please enter number "<<i+1<<":";

// Read and store

// the number.

cin >> currNum;

// Run the loop till the

// entered number is valid.

while(true)

{

// If the number is out of range,

// display an error message.

if(currNum>40 || currNum<1)

{

cout << "The number must between 1 and 40. ";

}

// Otherwise, if the number is

// already present in the array,

// display an error message.

else if(NoDuplicates(UserTicket, i, currNum) == 0)

{

cout << "No duplicate numbers are accepted. ";

}

//Otherwise if the number is valid,

// break out of the loop.

else

{

break;

}

// If the number was invalid,

// prompt the user to enter the number again.

cout << "Please enter another number:"<<endl;

cin >> currNum;

}

// Store the number in the array.

UserTicket[i] = currNum;

}

}

// Define the function GenWinNums().

void GenWinNums(int WinningNums[7])

{

int currNum;

// Run the loop to

// generate 7 numbers.

for(int i=0; i<7; i++)

{

// Generate a random number

// in the range 1-40.

currNum = (rand()%40) + 1;

//Run the loop till the

// generated number is valid.

while(NoDuplicates(WinningNums, i, currNum) == 0)

{

// If the generated number was

// a duplicate, generate another number.

currNum = (rand()%40) + 1;

}

// Store the number in the array.

WinningNums[i] = currNum;

}

}

// Define the function getWinnings().

string getWinnings(int numMatches)

{

// Return the winnings as

// per the number of matches.

switch(numMatches)

{

case 0:

case 1:

case 2:

return "SORRY NOTHING";

case 3:

return "FREE TICKET";

case 4:

return "NOT BAD - $100";

case 5:

return "LUCKY YOU! - $5,000";

case 6:

return "GREAT! - $100,000";

case 7:

return "JACKPOT - 1 MILLION";

}

return "Invalid Matches";

}

// Define the function displayResults().

void displayResults(string name, int UserTicket[], int WinningNums[])

{

int numMatches = 0;

string winnings;

// Run the loop to convert

// the name to uppercase.

for(int i=0; i<name.size(); i++)

{

name[i] = toupper(name[i]);

}

// Run the loop to find

// the number of matches.

for(int i=0; i<7; i++)

{

for(int j=0; j<7; j++)

{

if(UserTicket[i] == WinningNums[j])

{

numMatches++;

break;

}

}

}

// Get the winnings as per

// the number of matches.

winnings = getWinnings(numMatches);

// Display the results.

cout << endl

<< name << "'s LOTTO RESULTS" << endl;

cout << "------------------------"<<endl;

cout << "WINNING TICKET NUMBERS:";

// Run the loop to display

// the winning numbers.

for(int i=0; i<7; i++)

{

cout << setw(3) << WinningNums[i];

}

cout << endl;

cout << setw(13) << name << "'s TICKET:";

// Run the loop to display

// the user ticket.

for(int i=0; i<7; i++)

{

cout << setw(3) << UserTicket[i];

}

cout << endl;

cout << "RESULTS:"<<endl;

cout << "--------"<<endl;

cout << "Number Matches: " << numMatches << endl;

cout << "Winnings : " << winnings << endl

<< endl;

}

// Define the

// function menu().

void menu()

{

cout << "LITTLETON CITY LOTTO MODEL:"<<endl

<<"---------------------------"<<endl

<<"1) Play Lotto"<<endl

<<"q) Quit Program"<<endl

<<"Please make a selection:"<<endl;

}

// Define the

// main() function.

int main() {

// Set the random seed.

srand(time(NULL));

// Define an array to store

// the user ticket.

int UserTicket[7];

// Define an array to

// store the winning numbers.

int WinningNums[7];

char userChoice = '0';

string name;

// Run the loop till

// the user wants to quit.

while(userChoice != 'q')

{

// Display the menu.

menu();

// Read and store

// the user choice.

cin >> userChoice;

// Perform the required action

// as per the user choice.

switch(userChoice)

{

case '1':

cout << "Please enter your name:"

<< endl;

cin >> name;

getLottoPicks(UserTicket);

GenWinNums(WinningNums);

displayResults(name, UserTicket, WinningNums);

break;

// If the user chooses to quit,

// display a message.

case 'q':

cout << "Thank you for"

<<" using the program."<<endl;

break;

// Display an error message

// for invalid selection.

default:

cout << "Invalid selection."

<< endl;

}

}

// Return from

// the main() function.

return 0;

}

You might be interested in
Write an<br> algorithm and draw a flowchart to convert the length in feet to<br> centimeter
Simora [160]

Answer:

blah blah blah sh ut up read learn

3 0
3 years ago
The homogeneous, reversible, exothermic, liquid phase reaction: A근R Is being carried out in a reactor system consisting of an id
baherus [9]

Answer:

attached below

Explanation:

3 0
3 years ago
When two or more simple machines are combined they form
Volgvan
Compound machine is the answer
8 0
2 years ago
A closed, rigid tank is filled with a gas modeled as an ideal gas, initially at 27°C and a gage pressure of 300 kPa. If the gas
ch4aika [34]

Answer:

gauge pressure is 133 kPa

Explanation:

given data

initial temperature T1 = 27°C = 300 K

gauge pressure = 300 kPa = 300 × 10³ Pa

atmospheric pressure = 1 atm

final temperature T2 = 77°C = 350 K

to find out

final pressure

solution

we know that gauge pressure is = absolute pressure - atmospheric pressure so

P (gauge ) = 300 × 10³ Pa - 1 × 10^{5} Pa

P (gauge ) = 2 × 10^{5} Pa

so from idea gas equation

\frac{P1*V1}{T1} = \frac{P2*V2}{T2}   ................1

so {P2} = \frac{P1*T2}{T1}

{P2} = \frac{2*10^5*350}{300}

P2 = 2.33 × 10^{5} Pa

so gauge pressure = absolute pressure - atmospheric pressure

gauge pressure = 2.33 × 10^{5}  - 1.0 × 10^{5}

gauge pressure = 1.33 × 10^{5} Pa

so gauge pressure is 133 kPa

4 0
3 years ago
Do the following addition exercises by translating the numbers into 8-bit 2's complement binary numbers, performing the arithmet
Ganezh [65]

Answer:

I am attaching a file with the solution and explanation as the number character limit is exceeding.

Explanation:

Download docx
8 0
3 years ago
Other questions:
  • Prove the following languages are nonregular, once using the pumping lemma and once using the Myhill-Nerode theorem. When using
    15·1 answer
  • What is a rivet and how do tehey work
    14·1 answer
  • An electric kettle is required to heat 0.64 kg of water from 15.4°C to 98.2°C in six
    8·1 answer
  • A customer complains that the heater works sometimes, but sometimes only cold air comes out while driving. Technician A says tha
    14·1 answer
  • Determine how much concrete you will need for a slab which is 50 feet by 30 feet wide and 1 foot thick
    15·1 answer
  • Question
    8·1 answer
  • U Differentiate between rotation and revolution<br>of earth.​
    6·2 answers
  • Question Completion Status:
    6·1 answer
  • What is the difference between a series circuit and a parallel circuit?
    11·2 answers
  • All people<br><br><br>id 5603642259 pd 123456<br>on z o o m​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!