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
A 0.4-W cylindrical electronic component with diameter 0.3 cm and length 1.8 cm and mounted on a circuit board is cooled by air
Katyanochek1 [597]

Answer:

The surface temperature of the component 54.6 degrees celsius.

Explanation:

Please see attachment.

7 0
3 years ago
A column in a building is subjected to the following load effects:
vagabundo [1.1K]

Answer:

attached below

Explanation:

6 0
3 years ago
Hello, how are you? ​
Kisachek [45]

Answer:

Hello, I'm good. Thank you for asking

8 0
2 years ago
Read 2 more answers
The reason for the nature of the signal's value is: Not Linear Humans are Continuous The stock market closes once per day, and s
Serga [27]

Answer:

Explanation:

* Daily close of the stock market

  • The nature of the signal in value is <u>Discrete</u>, as the stock market closes once per day,and so is discrete time.
  • And the nature of the signal in time is continuous as the company are continuous.
8 0
3 years ago
A square-thread power screw has a major diameter of 32 mm and a pitch of 4 mm with single threads, and it is used to raise a loa
Valentin [98]

Answer:

54mm.

Explanation:

So, we are given the following data or parameters or information that is going to assist in solving this type of question efficiently;

=> "A square-thread power screw has a major diameter of 32 mm"

=> "a pitch of 4 mm with single threads"

=> " and it is used to raise a load putting a force of 6.5 kN on the screw."

=> The coefficient of friction for both the collar and screw is .08."

=> "If the torque from the motored used to raise the load is limited to 26 N×M."

Step one: determine the lead angle. The lead angle can be calculated by using the formula below;

Lead angle = Tan^- (bg × T/ Jh × π ).

=> Jh = J - T/ 2. = 32 - 4/2. = 30mm.

Lead angle = Tan^- { 1 × 4/ π × 30} = 2.43°.

Step two: determine the Torque required to against thread friction.

Starting from; phi = tan^-1 ( 0.08) = 4.57°.

Torque required to against thread friction = W × Jh/2 × tan (lead angle + phi).

Torque required to against thread friction =( 6500 × 30/2) × tan ( 2.43° + 4.57°). = 11971.49Nmm.

Step three: determine the Torque required to against collar friction.

=> 2600 - 11971.49Nmm = 14028.51Nmm.

Step four = determine the mean collar friction.

Mean collar friction = 14028.51Nmm/0.08 × 6500 = 27mm

The mean collar diameter = 27 × 2 = 54mm.

5 0
3 years ago
Other questions:
  • An engineer devises a scheme for extracting some power from waste process steam. The engineer claims that the steam enters the d
    15·1 answer
  • Three return steam lines in a chemical processing plan enter a collection tank operating at a steady state at 1 bar. Steam enter
    11·1 answer
  • A railcar with an overall mass of 78,000 kg traveling with a speed vi is approaching a barrier equipped with a bumper consisting
    15·1 answer
  • Methane (chemical formula Ch4), an important greenhouse gas, has a nearly constant mixing ratio throughout the lower atmosphere
    5·1 answer
  • Cuáles son los sentidos comunes que se pueden utilizar, para identificar un metal, gases o líquido
    7·1 answer
  • Let m be an integer in the set {0,1,2,3,4,5,6,7,8, 9}, and consider the following problem: determine m by asking 3-way questions
    12·1 answer
  • Which of following unit cell has the smallest atomic packing factor? (a) BCC unit cell (b) FCC unit cell (c) SC unit cell (d) HC
    5·1 answer
  • Witch measuring tool would be used to determine the diameter of a crankshaft journal
    5·1 answer
  • Pls answer and I will give a like!
    8·1 answer
  • What is the Crankshaft Turk ,Connecting rod Turk and Flywheel Turk for the 5a engine
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!