OK guys I'm back! This was actually a problem I asked you guys about before, but now I am trying to add a looped error checking. I want the program to say if the hour is wrong, if the seconds are wrong, or both. Then let the user retry it. I got the hour to work, but the other two are acting wierd. This is what I have so far:
Code:
#include <stdio.h>
main ()
{
int tfhour; /* Intialize tfhour, tfseconds, & twhour */
int tfseconds;
int twhour;
/* Prompt user for input of military time */
printf("Enter a 24-hour time (ex. 22:23): ");
/* Check to see if "seconds" input is valid */
/* and contines to check the hour */
while ( scanf("%d:%d", &tfhour, &tfseconds) == tfhour <=0 || tfhour > 24 )
{
printf("Not a valid hour time! Please enter a new one! "); /* If not, output */
}
while (tfseconds > 60 || tfseconds < 0)
{
printf("Not a valid seconds time! Please enter a new one! \n");
}
/* If between 1 & 12, make that input twhour */
if (tfhour <= 12 && tfhour > 0)
twhour = tfhour;
/* If between 13 & 24, subtract 12. Then place in */
/* twhour's postion */
if (tfhour >= 13 && tfhour <= 24)
twhour = (tfhour - 12);
/* Print twhour & seconds value with output */
printf("Equivalent 12-hour time: %d:%.2d ", twhour, tfseconds);
/* Checking for AM or PM. If the inputed value gives */
/* a 1 off when divided then it equals PM */
if (tfhour / 12 == 1)
printf("PM\n");
else
printf("AM\n");
return;
}
Any advice?
Thanks!