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
Do not answer pls thank you
astra-53 [7]

The answer is answered! Explanation:

4 0
3 years ago
Read 2 more answers
Match the types of AI to the correct automation tasks.
Maru [420]

Answer:

Theory of Mind : A robotic head has a face that recognizes and simulates emotions.

Self aware : A robot tries to protect itself from harm

Purely Reactive : A door automatically opens when a person steps in front of it.

Limited Memory : A personal assistant software tracks a persons travel routes and suggests shorter routes.

Explanation:

Artificial intelligence is simply a technology which enables automation. It enables system perform task without being explicitly controlled. Purely reactive systems do not store Data in memory, it simply observes what going on at the moment which is what it was programmed to do and takes a step. One the machine detects someone approaching up to a certain distance, it opens.

Limited Memory systems store information about the past and this enhances its Decison making, prediction engines, self driving cars use this kind of artificial intelligence.

Theory of Mind : Here, systems are trained to detect, understand and replicate what is understood. Once the robot identifies an emotion, it replicates it.

Self - Aware : An advanced level of AI, where systems will not only be able to replicate what they see, but also make conscious decisions as to which action to take in different circumstances.

5 0
3 years ago
What substance does light travel through before putting water in the cup
torisob [31]
Bend surface in water! Hopefully this helps, I looked it up!

6 0
3 years ago
What are the causes and solutions of social problems ?what are the causes and solutions of social problems ​
aksik [14]

Answer:

causes: unemployment, poverty,Lack of education,urbanization e.t.c

solutions:making people educated, giving people jobs

7 0
3 years ago
Anna Litical and Noah Formula are experimenting with the effect of mass and net force upon the acceleration of a lab cart. They
const2013 [10]

Answer:

manda a senha senha do brainly bloquearam os amigos bloquearam os amigos e você vai ver o meu perfil você vai ver o meu perfil você vai ver o meu perfil completo a minha amiga Jeciane estamos fazendo uma academia de lima e fazendo uma academia de lima e fazendo uma academia de lima e fazendo uma academia de lima e fazendo uma academia de lima e você vai ver o meu perfil completo a minha amiga Jeciane estamos fazendo uma academia de lima e você vai ver o meu perfil completo a minha amiga Jeciane estamos fazendo uma academia de lima e você vai ver o meu perfil completo a minha amiga Jeciane estamos fazendo uma academia de lima e você vai ver o meu perfil completo a minha amiga Jeciane estamos fazendo uma academia de lima e

Explanation:

Marcar como melhor porfavo

8 0
3 years ago
Other questions:
  • Your program will be a line editor. A line editor is an editor where all operations are performed by entering commands at the co
    12·1 answer
  • Use the concept that y = c, −[infinity] &lt; x &lt; [infinity], is a constant function if and only if y' = 0 to determine whethe
    8·1 answer
  • 3. Write down the total thermal resistance for a double-pipe heat exchanger. Show how to convert from total resistance to an ove
    12·2 answers
  • The cubic capacity of a four-stroke over-square spark-ignition engine is 245cc. The over-square ratio is (1.1) The clearance vol
    14·1 answer
  • 5. A non-cold-worked brass specimen of average grain size 0.01 mm has a yield strength of 150 MPa. Estimate the yield strength o
    10·1 answer
  • A 3-phase induction motor is being driven at a frequency of 80 Hz, and the motor speed is 1000 rpm. How many poles does the moto
    8·1 answer
  • W<br>n só<br>i<br>Eo<br>E<br>find the transfer function​
    9·1 answer
  • Which term describes a Cloud provider allowing more than one company to share or rent the same server?
    7·1 answer
  • For some metal alloy, the following engineering stresses produce the corresponding engineering plastic strains prior to necking.
    8·1 answer
  • HELP HELP HELP
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!