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;

}

Recommended Answers

All 3 Replies

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.