-
Notifications
You must be signed in to change notification settings - Fork 0
/
34-login-and-vote.c
128 lines (93 loc) · 2.77 KB
/
34-login-and-vote.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdio.h>
#include <string.h>
#define Total_People
#define Person1 "A"
#define Person2 "B"
#define Person3 "C"
#define Person4 "D"
int votesCount1=0, votesCount2=0, votesCount3=0, votesCount4=0, Wastedvotes=0;
void castVote(){
int choice;
printf("\n\n ### Please choose your Candidate ####\n\n");
printf("\n 1. %s", Person1);
printf("\n 2. %s", Person2);
printf("\n 3. %s", Person3);
printf("\n 4. %s", Person4);
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: Wastedvotes++;
break;
default: printf("\n Error: Wrong Choice !! Please retry");
getchar();
}
printf("\n thanks for vote !!");
}
void votesCount(){
printf("\n\n ##### Voting Statics ####");
printf("\n %s - %d ", Person1, votesCount1);
printf("\n %s - %d ", Person1, votesCount2);
printf("\n %s - %d ", Person1, votesCount3);
printf("\n %s - %d ", Person1, votesCount4);
printf("\n %s - %d ", "wasted Votes", Wastedvotes);
}
void getLeadingCandidate(){
printf("\n\n #### Leading Candiate ####\n\n");
if(votesCount1>votesCount2 && votesCount1>votesCount3 && votesCount1 >votesCount4)
printf("[%s]",Person1);
else if (votesCount2>votesCount3 && votesCount2>votesCount4 && votesCount2 >votesCount1)
printf("[%s]",Person2);
else if(votesCount3>votesCount4 && votesCount3>votesCount2 && votesCount3 >votesCount1)
printf("[%s]",Person3);
else if(votesCount4>votesCount1 && votesCount4>votesCount2 && votesCount4 >votesCount3)
printf("[%s]",Person4);
else
printf("----- Warning !!! No-win situation----");
}
int main()
{
char username[15];
char password[12];
printf("Enter your username:\n");
scanf("%s",&username);
printf("Enter your password:\n");
scanf("%s",&password);
if(strcmp(username,"Nayeem")==0){
if(strcmp(password,"12345")==0){
printf("\nWelcome.Login Success!");
int i;
int choice;
do{
printf("\n\n ******Welcome to Voting 2022 ******");
printf("\n\n 1. Cast Your Vote");
printf("\n 2. Check Vote Count");
printf("\n 3. Check leading Candidate");
printf("\n 0. Exit");
printf("\n\n Please enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1: castVote();break;
case 2: votesCount();break;
case 3: getLeadingCandidate();break;
default: printf("\n Error: Invalid Choice");
}
}while(choice!=0);
getchar();
}else{
printf("\nwrong password");
}
}else{
printf("\nUser doesn't exist");
}
return 0;
}