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 beam has been fixed to the floor by the pin at B and the roller at A as shown in figure 1 below.​
ahrayia [7]
What figure below???
3 0
3 years ago
Energy transfer in mechanical systems: During steady-state operation, a mechanical gearbox receives 70 KW of input power through
Degger [83]

Answer:

Heat transfer rate(Q)= 1.197kW

Power output(W)=68.803kW

3 0
3 years ago
There are 10 vehicles in a queue when an attendant opens a toll booth. Vehicles arrive at the booth at a rate of 4 per minute. T
dmitriy555 [2]

Answer:

as slated in your solution, if delay time is 2.30 mins, hence 9 vehicle will be on queue as the improved service commenced.

Explanation:

4 vehicle per min, in 2 mins of the delay time 8 vehicles while in 0.3 min average of 1 vehicle join the queue. making 9 vehicle maximum

3 0
3 years ago
How would you describe what would happen to methane if the primary bonds were to break?
erastova [34]

Answer:

All the bonds in methane (CH4CH4) are equivalent, and all have the same dissociation energy.

The product of the dissociation is methyl radical (CH3CH3). All the bonds in methyl radical are equivalent, and all have the same dissociation energy.

The product of that dissociation is methylene (CH2CH2). All the bonds in methylene are equivalent, and all have the same dissociation energy.

The product of that dissociation is methyne (CHCH) .

The C-H bonds in methane do not have the same dissociation energy as C-H bonds in methyl radical, which in turn do not have the same dissociation energy as the C-H bonds in methylene, which are again different from the C-H bond in methyne.

If (by some miracle) you were able to get all four bonds in methane to dissociate absolutely simultaneously, they would all show the same dissociation energy… but that energy, per bond broken, would be different than the energy required to break just one C-H bond in methane, because the products are different.

(In this case, it’s CH4→C+4HCH4→C+4H versus CH4→CH3+HCH4→CH3+H.)

To alter hydrocarbons you add enough energy to break a C-H bond. Why does only one bond break? What concentrates the energy on one C-H bond?

the weakest CH bond is the one that breaks. in plain alkanes it has to do with the molecular orbital interactions between neighboring carbon atoms. look at propane for example. the middle carbon has two C-C bonds, and each of those C-C bonds is strengthened by slight electron delocalization from the C-H bonds overlapping with the antibonding orbitals of the adjacent carbons.

since the C-H bonds on the middle carbon donate electron density to both of its neighbors, those two are weakest.

one of them will break preferentially.

which one actually breaks depends on the reaction conditions (kinetics). frankly it's whichever one ramdomly approaches a nucleophile first. when the nucleophile pulls of one of the H's, the other C-H bonds start to share (delocalize) the negative charge across the whole molecule. so while the middle C feels the majority of the negative charge character, the other two C's take on a fair amount as well...

by the way, alkanes don't really like to break and form anions like that.

a better example would be something like isopropyl iodide, where the C-I bond breaks and the I carries away the electron pair, forming a carbocation (also not particularly stable, but more so than the carbanion).

7 0
2 years ago
What are the advantages of studying a scheduled course over a more freeform one?
anyanavicka [17]

Answer:

Taking responsibility for your own learning makes it easier to identify your strengths and weaknesses. Once these have been identified you can work on a learning plan that focuses on the areas that you need most help with, increasing the speed of your learning, and build the skills you have been trying to perfect.

Explanation:

8 0
2 years ago
Read 2 more answers
Other questions:
  • the ____ method is the safest turning technique to use as it does not expose your hands to the airbags deployment area
    15·1 answer
  • A contractor needs to excavate 50,000 yd3 of silty clay and haul it with Caterpillar 69C dump trucks. Each truck can carry 30.9
    13·1 answer
  • The iron-blade plow allowed humans to increase food production during<br> what age?
    8·1 answer
  • In order to lift a lighter object on the other side, a boy placed 155 N of
    6·1 answer
  • Assignment # 2
    5·1 answer
  • PLS :(((( HELP HELPPPP
    13·1 answer
  • The pressure at the bottom of an 18 ft deep storage tank for gasoline is how much greater than at the top? Express your answer i
    15·1 answer
  • For a bolted assembly with eight bolts, the stiffness of each bolt is kb = 1.0 MN/mm and the stiffness of the members is km = 2.
    14·1 answer
  • All of the following are drum brake components mounted to the backing plate, EXCEPT:
    12·1 answer
  • 14. An engine is brought into the shop with a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!