syntax error near unexpected token 'while'

2

Programa que calcula el promedio de goles de un jugador por partido made by Bolanos Alfaro Jaime Sebastian

include<stdio.h>//para los comandos printf, scanf y getchar
int main(int argc, char *argv[ ])
{//abre funcion principal
    unsigned char nombreJugador[30]={'\n'}; short cantPartidos=0, goles=0, suma=0, conde=0; float promedio=0;
    printf("Este programa calcula el promedio de goles por partido de un jugador \n");
    printf("Ingrese el nombre del jugador: ");
    scanf("%[^\n]", nombreJugador);
    printf("Ingrese el numero de partidos: ");
    scanf("%hd", &cantPartidos);

    if(cantPartidos>0)
    {
        while (conde<=cantPartidos)
        {
            printf("Ingrese el numero de goles del partido %hd: ", conde);
            scanf("%hd", &goles);
            suma=suma+goles;
            conde= conde+1;
        }
        promedio=(float)suma/cantPartidos;
        printf("%s, tiene un promedio de %g goles por partido", nombreJugador, promedio);
        }
   else
            printf("\n\t La entrada no es correcta, vuelva a cargar el algoritmo");
getchar(); //atrapa el enter de scanf
getchar(); //mantiene estatica la pantalla
}

The program compiles, but at the time of executing it I get an error message

  

'syntax error near unexpected token' while ''

I do not know what it is that I hope you can help me. Mexico City of Mexico, programmed in mac with CodeBlocks .

    
asked by Sebastian Bolaños 13.04.2017 в 01:00
source

1 answer

4

I copied your code and it works for me, which tells me it's not a programming error but something related to your compiler.

Here I venture to speculate that maybe part of your code was copied from a Windows environment. according to this question unexpected token 'done' some users reported that :

  

If you are having this error you should have bad end of line Unix   use <LF> at the end of the file, while Windos uses <CR><LF> . <CR>   is interpreted as a character

Finally it is recommended to open a new file and write everything again manually so you avoid those problems between formats.

    
answered by 13.04.2017 в 02:04