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?