Evaluative activity hours per minute

0
  

Question (2): Make a program that receives an hour consisting of hour and minutes (a real number), calculate and show the time entered in minutes. Consider that:

     
  • For four-thirty (4:30), enter 4.30;
  •   
  • For four and fifty (4:50), you must type 4.50;
  •   
  • Minutes range from 0 to 59
  •   

What I tried to do:

#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>

int main(){
    setlocale(LC_ALL, "portuguese");
    float hora, min;


        printf("Insira as horas formatada 0.00: ");
        scanf("%f", &hora);

        min = hora;

            hora = (hora * 60);
            min = (min * 100)%100;
            hora = hora + min;

        printf("%2.0f minutos", hora);



}

But this error always appears:

  

C: \ Users \ Lelre \ Desktop \ ASSESSMENT ACTIVITY 2.c | 17 | error: invalid operands to binary% (have 'float' and 'int') |

I can not use mod with float values but is there any way to transform float to integer to get the remainder of the division and add to the minutes?

    
asked by anonymous 07.04.2017 / 17:03

1 answer

2

I think this is what you want.

#include<stdio.h>

int main() {
    float hora;
    printf("Insira as horas formatada 0.00: ");
    scanf("%f", &hora);
    float min = hora;
    hora = (int)hora;
    min = (min - hora) * 100;
    hora = hora * 60 + min;
    printf("%2.0f minutos", hora);
}

See running on ideone . And at Coding Ground . Also put it on GitHub for future reference .

    
07.04.2017 / 17:13