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.
#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;
}
Comments
Leave a comment