#include<stdio.h>
int main()
{
int x=0,y=0,z=0,d=0,vote,n,b_date,b_month,b_year,p_date,p_month,p_year,f_year,i;
char name[1000];
char add[1000];
printf("Enter Today's date:");
scanf("%d/%d/%d", &p_date, &p_month, &p_year);
printf("Enter the number of voters:");
scanf ("%d", &n);
for(i=1;i<=n;i++)
{
printf("Enter Name of voter %d:",i);
gets(name);
printf("\nEnter Adress of voter %d:",i);
gets(add);
printf("Enter Date of Birth of voter %d:",i);
scanf("%d/%d/%d",&b_date,&b_month,&b_year);
f_year = p_year - b_year;
if (f_year >= 18)
{
printf("Cast Your Vote\n");
printf("1)Vote for A\n");
printf("2)Vote for B\n");
printf("3)Vote for C\n");
printf("4)NOTA\n");
printf("Enter your choice:");
scanf("%d", &vote);
switch (vote)
{
case 1:
x++;
printf("Votes for A =%d\n", x);
printf("Votes for B=%d\n", y);
printf("Votes for C=%d\n", z);
printf("Votes for NOTA=%d\n", d);
break;
case 2:
y++;
printf("Votes for A=%d\n", x);
printf("Votes for B=%d\n", y);
printf("Votes for C=%d\n", z);
printf("Votes for NOTA=%d\n", d);
break;
case 3:
z++;
printf("Votes for A=%d\n", x);
printf("Votes for B=%d\n", y);
printf("Votes for C=%d\n", z);
printf("Votes for NOTA=%d\n", d);
break;
case 4:
d++;
printf ("Votes for A=%d\n", x);
printf ("Votes for B=%d\n", y);
printf ("Votes for C=%d\n", z);
printf ("Votes for NOTA=%d\n", d);
break;
default:
printf ("Invalid Choice\n");
}
}
else if(f_year<18)
{
printf("Sorry!You are not eligible to vote.\n");
}
}
if (x > y && x > z && x > d)
{
printf ("A won with %d votes", x);
}
else if (y > x && y > z && y > d)
{
printf ("B won with %d votes", y);
}
else if (z > x && z > y && z > d)
{
printf ("C won with %d votes", z);
}
else if (d > x && d > y && d > z)
{
printf ("Nobody won the election!");
}
return 0;
}
The code is for an votting machine it takes vote from user to decide who won.
What I have tried:
i have tried to add name and address of votters but its not working.The changes need to be made are between line 12 - 17