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
Name the major types of computer systems from slowest to fastest. ​
Vadim26 [7]

Answer:

Cache is the fastest and most expensive, RAM is slower and less expensive, and virtual memory is the slowest and least expensive type.

Explanation:

3 0
2 years ago
Anyone watch anime, i love stay kids and they sang the op for Tower of God XD
TEA [102]

Answer:

I do Stray kids and Tower Of God is good combo mannnn

6 0
3 years ago
Read 2 more answers
A cookie is stored on your device's memory or disk in what file format? 1.)video file
Natalka [10]

Answer:

text file format

4 this is the answer

4 0
1 year ago
Who is the three president of somalia​
Snezhnost [94]

Answer:

Siad Barre

Explanation:

3 0
3 years ago
Read 2 more answers
________ is the information about a file.
GalinKa [24]
Properties is the information about the file
4 0
3 years ago
Other questions:
  • Write an expression to print each price in stock_prices. sample output for the given program: $ 34.62 $ 76.30 $ 85.05
    6·1 answer
  • Describe two ways in which an organizer can assist in taking notes
    8·2 answers
  • Naseer has inserted an image into his document but needs the image to appear on its own line.
    14·2 answers
  • What are the first and the last physical memory addressesaccessible using
    10·1 answer
  • The set of instructions that directs the computer to perform a variety of tasks is known as a
    9·1 answer
  • Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If user
    15·1 answer
  • THIS IS PYTHON QUESTION
    11·1 answer
  • it says i have brainly plus subscripton but whenever i log onto brainly using my laptop, it says i don't have brainly plus and w
    12·1 answer
  • Que es una red de datos
    7·2 answers
  • The set of coordinating colors applied to backgrounds, objects, and text in a presentation is called:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!