-
Notifications
You must be signed in to change notification settings - Fork 0
/
First.c
111 lines (97 loc) · 2.76 KB
/
First.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#define CANDIDATE_COUNT
#define CANDIDATE1 "narendra modi"
#define CANDIDATE2 "MS Dhoni"
#define CANDIDATE3 "Virat Kohli"
#define CANDIDATE4 "puneet superstar"
int votesCount1 = 0, votesCount2 = 0, votesCount3 = 0, votesCount4 = 0, spoiledtvotes = 0;
void startVoting()
{
int choice;
printf("\n\n ### Please choose your Candidate ####\n\n");
printf("\n 1. %s", CANDIDATE1);
printf("\n 2. %s", CANDIDATE2);
printf("\n 3. %s", CANDIDATE3);
printf("\n 4. %s", CANDIDATE4);
printf("\n 5. %s", "None of These");
printf("\n\n Input your choice (1 - 4) : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
votesCount1++;
break;
case 2:
votesCount2++;
break;
case 3:
votesCount3++;
break;
case 4:
votesCount4++;
break;
case 5:
spoiledtvotes++;
break;
default:
printf("\n Error: Wrong Choice !! Please retry");
// hold the screen
getchar();
}
printf("\n thanks for voting !!");
}
void votesCount()
{
printf("\n\n ##### Voting Stats ####");
printf("\n %s - %d ", CANDIDATE1, votesCount1);
printf("\n %s - %d ", CANDIDATE2, votesCount2);
printf("\n %s - %d ", CANDIDATE3, votesCount3);
printf("\n %s - %d ", CANDIDATE4, votesCount4);
printf("\n %s - %d ", "Spoiled Votes", spoiledtvotes);
}
void getWinningCandidate()
{
printf("\n\n #### Winning Candiate ####\n\n");
if (votesCount1 > votesCount2 && votesCount1 > votesCount3 && votesCount1 > votesCount4)
printf("[%s]", CANDIDATE1);
else if (votesCount2 > votesCount3 && votesCount2 > votesCount4 && votesCount2 > votesCount1)
printf("[%s]", CANDIDATE2);
else if (votesCount3 > votesCount4 && votesCount3 > votesCount2 && votesCount3 > votesCount1)
printf("[%s]", CANDIDATE3);
else if (votesCount4 > votesCount1 && votesCount4 > votesCount2 && votesCount4 > votesCount3)
printf("[%s]", CANDIDATE4);
else
printf("----- Alert !!! No-win situation----");
}
int main()
{
int i;
int choice;
do
{
printf("\n\n ###### Welcome to Voting 2023 #####");
printf("\n\n 1. Start Voting");
printf("\n 2. Find Vote Count");
printf("\n 3. Find Winning Candidate");
printf("\n 0. Exit");
printf("\n\n Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
startVoting();
break;
case 2:
votesCount();
break;
case 3:
getWinningCandidate();
break;
default:
printf("\n Error: Invalid Choice");
}
} while (choice != 0);
// hold the screen
getchar();
return 0;
}