hi guys!!

The purpose of the program I am trying to do is to have an input number of 6 digits typed in and this should then be printed as an hour minute second format. for example 123456 would be 12:34:56

This is what I have but it isn't working in the slightest..??

include <stdio.h>

int main(int argc, char * argv []) {

int sixdigits;  

printf("Enter 24 hour time in HHMMSS format:\n");
scanf("%d", &sixdigits);

int hr = (sixdigits/10000);
int min = ((sixdigits/100)-(hr*100));
int sec = (sixdigits-(hr*10000)-(min*100));

if ((hr>=00 && hr<24) && (min>=00 && min<=59) && (sec>=00 && sec<=59)) {
    printf("%d : %d : %d\n", hr, min, sec);
} else { printf("Format must be HHMMSS\n");

return 0;


6 Years
Discussion Span
Last Post by Ancient Dragon

Your include header file should be preceded with a hash (#)

Edited by Milton Neal: fix typo


The minimum range for int is -32767 to +32767. If your compiler (also known as implementation) is at this minimum, int is not large enough to store 6 digits. However, many implementations have a much larger range so that may not be your problem. You may want to look values in <limits.h> to see what range your compiler supports.

Edited by pheininger: Add idea about <limits.h>


This is what I have but it isn't working in the slightest..??

That program worked ok for me using VC++ 2010 Express on Windows 7. If its broken for you then I suspect that pheininger is correct in his assessment. Change int sixdigits to long sixdigits

Edited by Ancient Dragon: correct

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.