Lottery Application Write a program that simulates a lottery. The program should
ID: 3770880 • Letter: L
Question
Lottery Application Write a program that simulates a lottery. The program should have an arrray of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element in the array. The user should enter five digits which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that match. For example, the following shows the lottery array and the user array with simple numbers stored in each. There are two matching digits (elements 2 and 4). lottery array: |7|4|9|1|3| user array: |4|2|9|7|3| The program should display the random numbers stored in the lottery array and the number of matching digits. If all of the digits match, display a message proclaiming the user as a grand prize winner.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int lottery[5], user[5],i,c=0;
for(i=0;i<5;i++)
{
lottery[i]=rand()%9;
cout<<"Enter No";
cin>>user[i];
}
cout<<"Lottery numbers are =";
for(i=0;i<5;i++)
{
cout<<lottery[i]<<"|";
}
cout<<"Users numbers are =";
for(i=0;i<5;i++)
{
cout<<user[i]<<"|";
}
cout<<"Matching numbers are=";
for(i=0;i<5;i++)
{
if(lottery[i]==user[i])
{
cout<<user[i]<<", ";
c++;
}
}
if(c==5)
{
cout<<"U r lottery Winer";
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.