0
I want to make a program where the user gives the number of candidates and their names, and then the vote is started until the user type order. Help?
#include<stdio.h>
#include<string.h>
int main()
{
char nome[30][30];
char vot[30];
int ponto[30];
int n,i,j,k,maior=0,aux;
char fim[] = "fim";
scanf("%i", &n);
for(i=0;i<n;i++)
{
gets(nome[i]);
}
printf("A votacao comecou\n");
for(i=0;i<=30;i++)
{
ponto[i]=0;
}
for(;;)
{
gets(vot);
k=strcmp(vot,fim);
if(k==0)
{
printf("A votacao terminou\n");
break;
}
for(i=0;i<n;i++)
{
j=stricmp(vot,nome[i]);
if(j==0)
{
ponto[i]=ponto[i]+1;
break;
}
}
}
for (i=0; i<n; ++i)
{
if (ponto[i]>maior) aux=i;
}
printf("O vencedor e:\n");
puts(nome[aux]);
return 0;
}
After defining
ponto
as an array with 30 elements, the last element of the array isponto[29]
; the elementponto[30]
there is no.– pmg