I'm trying to run the following code in eclipse but the console remains blank until i stop the program at which point the output "Enter next value (<=0 to quit)2130567168 minutes is 35509452 hours, 48 minutes." is repeated over and over.
It seems that scanf is putting some default value in for some reason... can't figure out why. I'm not seeing anything before the program is stopped so i thought it might have to do with printf not being flushed, but I made sure to use \n to force a flush.
Any ideas?
#include <stdio.h>
const int MIN_PER_HOUR = 60; // minutes per hour
int main(void)
{
int hour, min, left;
printf("Convert minutes to hours and minutes!\n");
printf("Enter the number of minutes (<=0 to Quit):\n");
scanf("%d", &min); // read number of minutes
while(min > 0){
hour = min / MIN_PER_HOUR; // truncated number of hours
left = min % MIN_PER_HOUR; // number of minutes left over
printf("%d minutes is %d hours, %d minutes.\n", min, hour, left);
printf("Enter next value (<=0 to quit)");
scanf("%d", &min);
}
printf("Done!\n");
return 0;
}