Originally Posted by
Matticus
You're welcome. I suggest you run the program with an input of 70, look at the output, then read the advice given by algorism from post #10.
Also, be sure to keep your code properly indented, as I've suggested.
Code:
#include <stdio.h>
int main(void) /* */
{
int addtime,hr,min,i=0;
char ampm;
printf("Please enter the hour:");
scanf("%d",&hr);
while(hr<0||hr>12)
{
printf("Please enter a number between (1-12)only:\n");
scanf("%d",&hr);
}
printf("Please enter the minutes:\n");
scanf("%d",&min);
while(min<0||min>59)
{
printf("Please enter a number between(0-59):\n");
scanf("%d",&min);
}
printf("Please enter 'A' for AM or 'P' for PM:\n");
scanf("%c",&m);
while(!(ampm=='A'||ampm=='P'))
{
printf("'A' or 'P' only please:\n");
scanf("%c",&m);
}
printf("How many minutes do you want to add?");
scanf("%d",&addtime);
while(addtime<1||addtime>800)
{
printf("Please enter a number between 1-800 only:\n");
scanf("%d",&addtime);
}
printf("%d:%.02d %cM\n",hr,min,ampm);
for(i=0;i<addtime;i++)
{
min++;
if(hr>12)
{
hr=hr-12;
}
if(min>59)
{
hr=hr+1;
min=0;
}
if(ampm=='A'&&hr==1)
{
ampm='P';
}
if(ampm=='P'&&hr==1)
{
ampm='A';
}
printf("%d:%.02d %cM\n",hr,min,ampm);
}
}
for some reason when the hour switches to 1 it actually prints 13:00 then it goes to 1:01?
Then the other problem is for some reason 'P' will switch to 'A' at hr=1 but 'A' will not switch to 'P' at hr=1 ?