Answer to Question #200291 in C++ for Shob

Question #200291

Write a function to generate lottery numbers using rand() function. This void function takes an int array with size 5. It generates five random digits

A void function called get user input takes an int array, and an int parameter size. This array should have the same size as the lottery[] array.

A function that compares the two arrays, lottery[] and user[] and keeps count of the matching digits and returns the count.

A void function to display the lottery[] and user[] arrays.

Next output the number of matches. If the matches count is 5, announce that the user is a grand prize winner.


1
Expert's answer
2021-05-29T03:37:02-0400


#include <iostream>


using namespace std;


//Write a function to generate lottery numbers using rand() function. 
//This void function takes an int array with size 5. It generates five random digits
void generateLottery(int lottery[5]){
    for(int i=0;i<5;i++){
        lottery[i]=rand()%10;
    }
}
//A void function called get user input takes an int array, and an int parameter size. 
//This array should have the same size as the lottery[] array.
void getUserInput(int user[],int size){
    cout<<"\nEnter your input:";
    for(int i=0;i<5;i++){
        cin>>user[i];
    }
}
//A function that compares the two arrays,
//lottery[] and user[] and keeps count of the matching digits and returns the count.
int compareArrays(int user[], int lottery[]){
    int matches = 0;
    for (int i = 0; i < 5; i++) {
        if (user[i] == lottery[i]) {
            matches++;
        }
    }
    return matches; 
}
//A void function to display the lottery[] and user[] arrays.
void display(int user[], int lottery[]){
    cout<<"The lottery number is: ";
    for (int i = 0; i < 5; i++){
        cout<<lottery[i];
    }
    cout<<endl;
    cout<<"\nYour number is: ";
    for (int i = 0; i < 5; i++){
        cout<<user[i];
    }
    cout<<endl;
    //Next output the number of matches. If the matches count is 5, 
    //announce that the user is a grand prize winner.
    int n=compareArrays(user,lottery);
    if (n==5){
        cout<<"\nYou are a grand prize winner";
    }
}


int main()
{   
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog