In the output scenarios you use printf("%02d = %02d:%02d am\r\n", i, First, Last);
Each %02d
tells the compiler you want a two-digit number with leading zeroes.
However, the first %02d
in each output line should be %04d
since we want a number 4-digits long with leading zeroes.
Try that instead.
Three words on coding style for beginners: (if you believe ignorance is bliss please disregard)
- main should always be declared as a int instead of a void. Assuming no errors,
return 0;
at the end is fine. getch();
and alsosystem("pause");
at the end of a program are bad form and you'll want to break that habit early on. Put in the return value at the end of main and, once you've learned to use the debugger, set a breakpoint there. This keeps your window open until you're done with it.- Using
#include<conio>
makes your code "non-portable" (i.e. could break this code on another C compiler on another platform) and is discouraged. Getting rid of thegetch();
means you can get rid of#include<conio>
.
But most importantly, good luck and have fun coding.