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
IgorC [24]
3 years ago
12

Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with

7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element. Then ask the user to input 7 numbers into another array. Display the lottery numbers and the user’s chosen numbers. Then display if the user is a lottery winner or should try again. Continue this loop until the user types in ‘x’ to quit.
Computers and Technology
1 answer:
Nikolay [14]3 years ago
5 0

Answer:

/******************************************************************************

                             Online C++ Compiler.

              Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

bool equal(int sys[],int user[])

{

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

{

 if(sys[i]!=user[i]){

     return false;

 }

}

return true;

}

int main()

{

int sys[7];

int user[7];

int min=0

;int max=9;

string userinput;

while(0==0){

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

{

    sys[i]=rand() % (max - min + 1) + min;

}

cout <<endl;

   cout<<"enter numbers"<<endl;

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

{

 getline (cin,userinput);

    if(userinput=="x"){

        return 0;

    }

    else{

 stringstream(userinput) >> user[i];

   

    }

}

     cout<<"User number"<<endl;

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

{

    cout << user[i];

}

    cout<<"system number"<<endl;

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

{

    cout << sys[i];

}

if(equal(sys,user))

{

   cout<<"You won !"<<endl;

}else {

       cout<<"Try again :("<<endl;

}

}

   return 0;

}

Explanation:

Using c++ rand function generate a random number between 0-9.

Formula for random number is rand (max-min +1)+min.

Run this in a loop for 7 time and store each number to an array index in sys array which is for system generated number.

now using string take input from user and check if input is x close program else use stringstream to parse input string to int and store it in user array. Stringstream is a cpp header file used for parsing and handling of strin g inputs. Run this program in loop for 7 times.

Now create a function of type boolean denoted by "bool". This will take both arr as parameter and check if both are equal or not. It compares eac index of user array against each index of sys array and if both values are not equal returns false.

You might be interested in
To use an outline for writing a formal business document, what should you
nydimaria [60]

Answer: D. enter each major point from the outline on a separate line

6 0
4 years ago
A mother takes her child to the pediatrician because her right eye is red, itchy, with a mucus discharge coming from the eye. Th
allochka39001 [22]

Answer:

H10.021

Explanation:

7 0
3 years ago
What is a scientific inquiry?
nlexa [21]
Scientific inquiry<span> refers to the diverse ways in which </span>scientists<span> study the natural world and propose explanations based on the evidence derived from their work.</span>
8 0
3 years ago
How might the design be changed so that additional copies of print statements would not be needed?
bogdanovich [222]

A design be altered so that additional copies of print statements would not be needed by changing the format spring.

<h3>What is the aim of a print statement?</h3>

The PRINT statement is known to be often sent data so that it is taken to the display terminal or to another kind of print unit.

Note that A design be altered so that additional copies of print statements would not be needed by changing the format spring.

Learn more about design from

brainly.com/question/1020696

#SPJ1

5 0
2 years ago
Which type of electronic community is Usenet?
suter [353]
<span>Newsgroup
 should be the answer</span>
7 0
3 years ago
Read 2 more answers
Other questions:
  • A linear representation of a hierarchical file directory is known as what?
    6·1 answer
  • Describe encryption at gateways in thePresentation layer of the OSI Reference Model
    6·1 answer
  • How do you increase the amount of data in a sampled Google Analytics report?
    8·1 answer
  • Identify the mobile device deployment option that gives the user flexibility to select a device, but allows the company to contr
    5·1 answer
  • Unless you explicitly initialize global variables, they are automatically initialized to
    5·1 answer
  • Write a Program in C language using arrays:
    14·1 answer
  • Which of the following is considered a modern method of communication?
    7·2 answers
  • I have been charged for brainly plus yet I still have to watch ads why? What do I do?
    12·2 answers
  • 4.2 lesson practice help plzs
    6·1 answer
  • Scrieți un program care citește un număr natural n și determină suma cifrelor divizibile cu 3 ale lui n.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!