+ 1
What is the problem with this military time code coach problem of mine?
#include<stdio.h> #include<string.h> char str[100]; char spc[100]; int main() { int i, j,k,x,n,m,len; fgets(str, 100, stdin); for(i=0;i<strlen(str);i++) { if(str[i]==58) { for(j=i;j<strlen(str);j++) { str[j]=str[j+1]; } } } for(k=0;k<4;k++) { spc[k]=str[k]; } //printf("%s", spc); x = atoi(spc); //printf("%d",x); m = x/100; n = x%100; len = strlen(str); if(str[len-3] == 80) { m = m+12; if(n < 10) { printf("%d:0%d",m,n); } else { printf("%d:%d",m,n); } } else { if(m < 10 && n<10 ) printf("0%d:0%d",m,n); else if(m < 10 && n >= 10) printf("0%d:%d",m,n); else if(m >= 10 && n < 10) printf("%d:0%d",m,n); else if(m >= 10 && n >= 10) printf("%d:%d",m,n); } }
4 Answers
+ 7
Put your code in a script on sololearn playground instead of copying everything into the description â it is hardly readable and we can't test it.
Go to Code section, click +, select the programming language, insert your code, save.
Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
+ 2
Just tested:
Input: 01:30PM
Output: 13:30
Doesn't already work as intended?
+ 1
Also use clearer variable names and some comments. Helps a lot, including yourself, in the near future.
+ 1
And please, insted of ASCII values use the characters (e.g. 'P' instead of 80)