1. ## Clockwork puzzle

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...

2. > 18:00 - 17:00 = 1 hour
Convert both times into minutes

So you have
diff = (18*60+0) - (17*60+0)

Which gives you the time difference in minutes

To turn this back into hours and minutes, its just
diff_hr = diff / 60;
diff_mn = diff % 60;

3. ## Not quite sure if I got that...

My code now:

#include <stdio.h>
int main ( )
{
int hours;
int min;
int hours2;
int min2;
int total;
int minutes, time_h, time_min;
int diff;
int diff_hr;
int diff_mn;
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("\n");
minutes = 1440 - (min + 60*hours);
diff = (hours*min) - (hours2*min2);
diff_hr = diff / 60;
diff_mn = diff % 60;
time_h = minutes / 60;
time_min = minutes % 60;
printf("test1 %d minutes test2 %d minutes %d %d", total, diff, diff_hr, diff_mn);
}
else
printf("You gave incorrect clock time!");
return 0;
}

Didn't help... but I'm not sure if you meant this...

4. FOCUS!!!!!
Did you see any hours * minutes ?
Does hours * minutes make any sense?

Code:
```#include <stdio.h>

int main ( ) {
int hours;
int min;
int hours2;
int min2;
int diff;
int diff_hr;
int diff_mn;

printf("Give start time in form h min (example 12:34):");
scanf("%d:%d", &hours, &min);
printf("Give end   time in form h min (example 12:34):");
scanf("%d:%d", &hours2, &min2);

diff = ( hours2 * 60 + min2 ) - ( hours * 60 + min );
diff_hr = diff / 60;
diff_mn = diff % 60;
printf("Difference is %d:%d\n", diff_hr, diff_mn);

return 0;
}```