### Time needed for homework

I am currently working on a program that calculates the total time needed to finish English and Mathematics homework. However, it freezes when I finish inputting. Please help.

SAMPLE INPUT 1:
66
99
SAMPLE OUTPUT 1:
Needed time to finish all homework: 2 hours 45 minutes

SAMPLE INPUT 2:
33
3
SAMPLE OUTPUT 2:
Needed time to finish all homework: 0 hour 36 minutes
 ``1234567891011121314151617181920`` ``````#include #include using namespace std; int main(){ printf("Homework Time Calculator\n"); int eng,math,time,hour=0; printf("Format: xx minutes\n"); printf("English> "); scanf("%d",&eng); printf("Mathematics> "); scanf("%d",&math); time=eng+math; while(time>=60){ hour++; } if(hour>1) printf("Needed time to finish all homework: %d hours %d minutes\n",hour,time); else printf("Needed time to finish all homework: %d hour %d minutes\n",hour,time); system("pause"); return 0; }``````
 ``123`` ``````while(time>=60){ hour++; }``````

This is an infinite loop as there is nothing in the while loop to modify the value of time, so if time is >= 60 before the loop, the loop will run forever. Solution - Modify the value of time in the loop (time = time - 60;).

There is an analytical solution too, which does not require a loop. Division and modulo.
Topic archived. No new replies allowed.