Is there anything wrong with my code? It's a program that coverts 24-h time format to 12-h time format, and only takes a four-digit integer as input.
ex. input = 0000 then output should be 00:00 a.m.
When I submit my code to schools online judge, it doesn't accept all inputs, but I can't find out the problem.
#include <stdio.h>
int main(void)
{
int morning, hour, min;
scanf("%02d%02d", &hour, &min);
if (hour > 23 || min > 59)
{
return 1;
}
//check am pm
if (hour >= 12)
{
morning = 1;
if (hour > 12)
{
hour -= 12;
}
}
else
{
morning = 0;
}
//print the result
if (morning == 0)
{
printf("%02d:%02d a.m.", hour, min);
}
else
{
printf("%02d:%02d p.m.", hour, min);
}
return 0;
}