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
Identify the selector in the following CSS code:
SashulF [63]

Answer:

The right answer is: Option A. h3

Explanation:

The purpose of using selectors in CSS is to find the elements in the HTML page to which the formatting will be applied.

Different type of selectors are used in CSS.

In the given code, h3 is the selector.

All the <h3> elements on the page will be of orange color and will have font size 12.

Hence,

The right answer is: Option A. h3

6 0
3 years ago
Why is Apple using social media ?
jeka57 [31]

Apple uses social media to promote their products and increase user-engagement. This is a very effective method of advertising.

6 0
3 years ago
Flowgorithm, Design a program that prompts the user to enter a number within the range of 1 through 10. The program should displ
kherson [118]

Answer:

Step by step code along with explanation and output is given below

Explanation:

We can solve this problem using if elif else approach

def main():

# prompts the user to enter an integer from 1 to 10

 num = int (input('Enter a number in the range of 1 to 10:\n'))

# using the if elif print out the roman numeral from 1 to 10

 if num == 1:

   print ('Roman Numeral for 1 is I')

 elif num == 2:

   print ('Roman Numeral for 2 is II')

 elif num == 3:

   print ('Roman Numeral for 3 is III')

 elif num == 4:

   print ('Roman Numeral for 4 is IV')

 elif num == 5:

   print ('Roman Numeral for 5 is V')

 elif num == 6:

   print ('Roman Numeral for 6 is VI')

 elif num == 7:

   print ('Roman Numeral for 7 is VII')

 elif num == 8:

   print ('Roman Numeral for 8 is VIII')

 elif num == 9:

   print ('Roman Numeral for 9 is IX')

 elif num == 10:

   print ('Roman Numeral for 10 is X')

# using the else print out error message whenever user enters any other number not listed above

 else:

   print ('Error! Wrong Input')

# call the main function

main()

Output:

Enter a number in the range of 1 to 10:

6

Roman Numeral for 6 is VI

Enter a number in the range of 1 to 10:

15

Error! Wrong Input

6 0
2 years ago
Write structured pseudocode to show the following: when you are on time for work you have time to buy coffee
faltersainse [42]

Answer:

If( on_time == True) {

     print("Coffee")

} else {

    print("No Coffee")

}

Explanation:

Step 1 evaluate with a boolean variable if you are on time

If( on_time == True) {

Step 2 if true you have coffee

print("Coffee")

Step 3 if false you have not coffee

print("No Coffee")

3 0
3 years ago
Give me reasons why Harry Potter is bad and anime is better
andrew11 [14]

Answer:

Harry Potter is Horrible

Explanation:

Anime is simply better... some 14 year old who has some horrible scar just simply isnt cool! with anime, you have demon slayer, attack on titan, naruto etc. Also pokemon could beat harry potter any day. please just give it a chance :)

4 0
1 year ago
Other questions:
  • A(n) _____ is a simple database program whose records have no relationship to one another.
    10·1 answer
  • What is an advantage of sharing documents in PDF format instead of Word format?
    6·2 answers
  • In the context of web and network privacy issues, new employees in an organization have to sign a(n)__________ before they acces
    15·2 answers
  • Ray has to type an invoice using the QWERTY keyboard. Along with letters and numbers, he also has to insert the dollar sign. Whi
    13·1 answer
  • John would like to move from the suburbs into the city, but the rent in the city is very high. John has found an apartment he re
    13·1 answer
  • Java provides a(n) ____ class, which contains many useful methods for manipulating arrays.
    5·1 answer
  • Question 2 Unsaved Which of these is NOT an example of an emerging technology? Question 2 options: Sixth Sense Close Range Drone
    6·1 answer
  • HELP ME ASAP PLS BEING TIMED
    8·2 answers
  • The reason the Code uses the term ____ instead of motor is that, in many instances, the motor is inside an enclosure and is out
    12·2 answers
  • Greg works outside. He is often found cutting grass and making the local park grounds look nice for guests.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!