OK I got this so far:
Code:
#include <stdio.h>
main ()
{
int tfhour;
int tfseconds;
int twhour;
printf("Enter a 24-hour time (ex. 10:23): ");
scanf("%d:%d", &tfhour, &tfseconds);
if (tfseconds > 60 || tfseconds < 0)
{
printf("Not a valid seconds time!\n");
return;
}
if (tfhour <= 12 && tfhour >= 0)
printf("Equivalent 12-hour time: %d:%.2d AM\n", tfhour, tfseconds);
else if (tfhour >= 13 && tfhour <= 24)
{
twhour = (tfhour - 12);
printf("Equivalent 12-hour time: %d:%d PM\n", twhour, tfseconds);
}
else
printf("Not a valid hour!\n");
return;
}
I got two questions!
1) I need to get two zeros on the seconds output instead of a single digit. I know why it is doing it..lol But I need to know how to fix it?
2) As far as military time is concerned 12:00 is 12:00 pm while 24:00 is 12:00 AM. How can I get that to work out like that? Another if statement maybe?
Any help would be appreciated!