forked from tridibsamanta/CPP_Beginner_to_Expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CPP028_Lottery_Exercise.cpp
52 lines (40 loc) · 1.04 KB
/
CPP028_Lottery_Exercise.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Author: Tridib Samanta
* Created: 27.01.2020
**/
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void lottery(int, int);
int main() {
int total_people,total_winners;
cout<<"Enter the total number of people : "<<endl;
cin>>total_people;
cout<<"Enter the total number of prizes : "<<endl;
cin>>total_winners;
lottery(total_people,total_winners);
return 0;
}
void lottery(int total_balls, int balls_to_draw)
{
if(total_balls < balls_to_draw) {
cout<<"Draw not possible";
return;
}
cout<<"The winners are : "<<endl;
srand(time(NULL));
int *balls = new int[balls_to_draw];
for(int i=0;i<balls_to_draw;i++) {
balls[i] = rand() % total_balls + 1;
for(int j=0;j<i+1;j++) {
if(balls[i]==balls[j] && i!=j) {
i--;
break;
}
else if(j==i)
cout<<balls[i]<<endl;
}
}
delete[] balls;
}