"expected expression before 'int'" error

0

I was following this example, but it was done in Windows, so I used <conio.h> . When I try to run on Linux I get 2 errors: one in *h=int(tempo); , I do not understand why, and the other in getch . How can I replace them?

#include <stdio.h>

void horario(float tempo, int *h, int *m)
{
    *h=int(tempo);
    *m=(tempo-*h)*60;
}

int main ()
{
    int hora,minuto;
    char resp;
    float t;

    do
    {
        printf("Digite o horario na forma centesimal: ");
        scanf("%f",&t);
        horario(t,&hora,&minuto);
        printf("Horario: %02d:02%d\n",hora,minuto);
        printf("Quer calcular outro horario? (S/N):");
        resp=getch();
    } while (resp=='S');
    getch();
    return 0;
}
    
asked by anonymous 25.03.2014 / 00:12

2 answers

1

You had two problems:

  • Typecast badly done.
  • getchar instead of getch

    void horario(float tempo, int *h, int *m){
        *h=(int)tempo;
        *m=(tempo-*h)*60;
    }
    
    int main(){
        int hora,minuto;
        char resp;
        float t;
        do
        {
            printf("Digite o horario na forma centesimal: ");
            scanf("%f",&t);
            horario(t,&hora,&minuto);
            printf("Horario: %02d:02%d\n",hora,minuto);
            printf("Quer calcular outro horario? (S/N):");
            getchar();
            resp = getchar();
        } while (resp=='S');
        getchar();
        return 0;
    }
    
  • 25.03.2014 / 00:18
    1

    To cast, use the desired type in parentheses followed by

    (int)tempo // cast de tempo para tipo int: correcto
    int(tempo) // incorrecto: aparenta ser a chamada da funcao int com argumento tempo
    

    You can replace getch() with getchar() (prototype in <stdio.h> that you included).

        
    25.03.2014 / 00:16