I really need some help with this; I do not see how to do this without arrays. I
ID: 3760429 • Letter: I
Question
I really need some help with this; I do not see how to do this without arrays. I am not supposed to use them, and I have been trying all week.
Write a program to simulate a lottery drawing that uses balls numbered from 1 to 10.
Assume that five balls are drawn at random. All five balls for each drawing are unique. Allow the user to enter the number of lottery drawings to simulate. Validate the input of lottery drawings.
What percentage of the time does the result contain five even numbers in the simulation? What percentage of the time does the number 7 occur in the five numbers in the simulation? What percentage of the time do the numbers 1, 2, 3, 4 and 5 occur in simulation (in any order)?
Use at least three functions:
Function to get number of lottery drawings and validate
Function to generate unique random numbers (no duplicate numbers in a roll)
Function to calculate percentages
Your program should run as long as user would like.
SAMPLE OUTPUT:
Enter number of lottery drawings =>-4
Number of lottery drawings must be greater than 0!
Please re-enter number of lottery drawings =>5
Roll #1
5 9 6 4 10
Roll #2
10 9 7 3 2
Roll #3
6 5 3 1 4
Roll #4
5 6 2 4 3
Roll #5
10 1 9 8 4
Percentages of all even = 0%
Percentages of sevens = 20%
Percentages of all 1-2-3-4-5 order = 0%
Another round for the lottery? Type 1 for yes, any other number for no: 1
Enter number of lottery drawings =>3
Roll #1
4 10 6 9 7
Roll #2
1 5 8 9 3
Roll #3
2 10 7 6 3
Percentages of all even = 0%
Percentages of sevens = 66.6667%
Percentages of all 1-2-3-4-5 order = 0%
Another round for the lottery? Type 1 for yes, any other number for no: 2
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int n,c7=0,cev=0,i,j,c=0,ans=1,a,pev,pc7;
while(ans==1)
{
cout<<"Enter number of lottery drowings =>";
cin>>n;
if(n<1)
{
cout<<"Number of lottery drawings must be greater than 0!";
cout<<"Please re-enter number of lottery drawings =>";
cin>>n;
}
for(i=1;i<=n;i++)
{
cout<<"Roll #"<<i<<endl;
for(j=1;j<=5;j++)
{
a=rand()%10;
cout<<a<<" ";
if(a==7)
c7++;
if(a%2==0)
cev++;
}
if(cev==5)
c++;
cev=0;
cout<<endl;
}
pev=100*c/n;
cout<<"Percentages of all even ="<<pev<<"%"<<endl;
pc7=100*c7/5;
cout<<"Percentages of seven ="<<pc7<<"%"<<endl;
cout<<"Another round for the lottery? Type 1 for yes, any other number for no:";
cin>>ans;
}
}