Incrementing minutes for 12hour time?
Hello I am trying to take input from user for a given 12 hour clock time, then ask how many minutes to add to it, then print increments of each minute until the sum of those minutes is reached. I am having trouble with incrementing to the neccessary hour. Any ideas?
Code:
#include <stdio.h>
main()
{
int addtime,stophr,stopmin,hr=12,min=0;
printf("How many minutes do you want to add?");
scanf("%d",&addtime);
stophr=(min + addtime/60) + hr;
stopmin=(min + addtime)%60;
if(stophr>12)
{
stophr=stophr-12;
}
if(stopmin>59)
{
stopmin=stopmin-60;
}
printf("%d:%.02d\n",hr,min);
while(hr!=stophr && min!=stopmin)
{
min++;
if(hr>12)
{
hr=hr-12;
}
if(min>59)
{
hr=hr+1;
min=0;
}
printf("%d:%.02d\n",hr,min);
}
printf("%d:%.02d\n",stophr,stopmin);
}