Code:
#include <stdio.h>
int main(int argc, char * argv[]){
#define SEC_PER_MIN 60
#define MIN_PER_HOUR 60
#define ERROR_MSG "Format must be HHMMSS"
int sec, min, hour;
printf("Enter 24 hour time in HHMMSS format:\n");
scanf("%d %d %d", &hour, &min, &sec);
if (hour>23 || min>59 || sec>59){
printf("No such time\n");
}
if (hour<0 || min<0 || sec<0){
printf("No such time");
}
else {
printf("The time is %d:%d:%d\n",hour, min, sec);
}
return 0;
and I enter any number i.e. 231314
I get no output?
and even a number like 251617 which is not in the format I should get an output "No such time!"
but if I enter characters i.e. ahdbsh, then I get "No such time"
which is what I want but I need it for numbers to.
Any thoughts on what mistakes I have made
Thanks.
Last edited by a moderator: