Okay, I'm trying to create calculator that counts times like:
18:00 - 17:00 = 1 hour
I have most of the code ready, but I'm getting wrong answers, there must be error somewhere, but I can't find it... here's the code:
#include <stdio.h>
int main ( )
{
int hours;
int min;
int hours2;
int min2;
int total;
int minutes, time_h, time_min;
printf("\Give first time in form h min (example 12 34):");
scanf("%d %d", &hours, &min);
printf("\Give second time in form h min (example 12 34):");
scanf("%d %d", &hours2, &min2);
if ((hours >= 0)&&(hours <=23)&&(min >= 0)&&(min<=59))
{
total = hours / 60 + min - hours2 / 60 + min2;
printf("%d", total);
printf("\n");
minutes = 1440 - (min + 60*hours);
time_h = minutes / 60;
time_min = minutes % 60;
printf("The time was %d minutes", total);
}
else
printf("You gave incorrect clock time!");
return 0;
}
Don't mind about the time_h and time_min, those don't have anything to do with the problem I'm trying to solve now...



LinkBack URL
About LinkBacks



