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
How old are legos? Who created them? Why did they create them?
Sunny_sXe [5.5K]
“How old are the legos” 89 years old.


“Who created them?” Ole Kirk Christiansen.


“Why did they created them?” As a you man, Christiansen turned his love of whittling and playing with wood into a Business and, in 1916, he opened his own shop. Since times were so hard, Christiansen made the hard decision to use his wood to create inexpensive goods that might actually sell. Among them were Cheap toys.





Hope this helps•


Bye~



•Kate•
4 0
2 years ago
Millions of years ago, the Sierra Nevada region began to be uplifted along a crack in Earth's crust. The region on the other sid
Evgen [1.6K]

Answer:  The correct answer is :  Fault block mountain with rough edges and steep cliffs

Explanation:  Snowy saws are an example of a mountain chain blocked by faults. The snowy mountains were formed because the tectonic movement forced some segments of the earth's crust up into irregular pieces and others down.

8 0
3 years ago
The combustion chamber has different shapes depending on the make and model of the engine. True or false
Alisiya [41]

Answer:

svdsdfdfsdfssdf

Explanation:

fsdsdfsdffsdsfdsdf

5 0
2 years ago
I have a question.What does DIY mean?
alexdok [17]

Answer: It means "Do it yourself".

Explanation: You're welcome!

6 0
2 years ago
Read 2 more answers
Block A hangs by a cord from spring balance D and is submerged in a liquid C contained in beaker B. The mass of the beaker is 1.
nikitadnepr [17]

Answer:

a)  m_e= 3.05 Kg

b)  \rho=1072.3kg/m^3

c)  m_e= 3.05 Kg

Explanation:

From the question we are told that:

Beaker Mass m_b=1.20

Liquid Mass m_l=1.85

Balance D:

Mass m_d=3.10

Balance E:

Mass m_e=7.50

Volume v=4.15*10^{-3}m^3

a)

Generally the equation for Liquid's density is mathematically given by

m_e=m_b+m_l+(\rho*v)

\rho=\frac{7.50-(1.2+1.85)}{4.15*10^{-3}}

\rho=1072.3kg/m^3

b)

Generally the equation for D's Reading at A pulled is mathematically given by

m_d = mass of block - mass of liquid displaced

m_d=m- (\rho *v )

m=3.10+ (1072.30 *4.15*10^{-3}m^3 )

m=18.10kg

c)

Generally the equation for E's Reading at A pulled is mathematically given by

m_e=m_b+m_l

m_e = 1.20 + 1.85

m_e= 3.05 Kg

6 0
3 years ago
Other questions:
  • These tadpoles are confined to a limited environment. What are they all competing for in that environment
    12·2 answers
  • Describe the steps, tools, and technology needed in detail and
    12·1 answer
  • Answer the following questions, and very briefly explain your answer:
    5·1 answer
  • The working section of a transonic wind tunnel has a cross-sectional area 0.5 m2. Upstream, where the cross-section area is 2 m2
    10·1 answer
  • Complete the following sentence. Engineers explore biology, chemistry, and physics for use in scenarios.
    8·2 answers
  • 1)A wheel is used to turn a valve stem on a water valve. If the wheel radius is 1 foot and the stem, (axle), radius is .5 inches
    10·1 answer
  • The Bureau of Labor and Statistics predicted that the field of biomedical engineering would increase by 62 percent over the comi
    5·1 answer
  • 1. Given: R= 25 , E = 100 V<br> Solve for I
    5·1 answer
  • The resistance of a copper wire 200 m long is 21 Q. If its thickness (diameter) is 0.44 mm, its specific resistance is around___
    11·1 answer
  • Most goals
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!