Doubt about the use of 'for' in voting system

0

I want to make a program where the user gives the number of candidates and their names, and then the voting is started until the user types end. 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;

}
    
asked by anonymous 07.06.2015 / 20:43

1 answer

2

In the last cycle

    for (i=0; i<n; ++i)
    {
        if (ponto[i]>maior) aux=i;
    }

The variable maior does not change its value. It started 0 and continues 0 at the end of the cycle.

    
07.06.2015 / 20:48