- 1
Military Time Code Error !!
I written military Time Code , I don't know what went wrong it not running successfully , please help me. !!! https://www.sololearn.com/coach/70?ref=app
2 ответов
0
Just now I tried and runned successfully ! Anyways thank you for your response RDC
#include <iostream>
using namespace std;
int main() {
string b;
char s[8];
int i,l=0;
getline(cin,b);
for(i=0;b[i]!='\0';i++)
l++;
l=l-1;
if(l==6){
s[0]='0';
for(i=1;i<8;i++)
s[i]=b[i-1];
}
else{
for(i=0;i<8;i++)
s[i]=b[i];
}
l=7;
if((s[l-1]=='A'&&((((s[0]-48)*10)+(s[1]-48))!=12))||(s[l-1]=='P'&&((((s[0]-48)*10)+(s[1]-48))==12))){
for(i=0;i<l-2;i++)
cout<<s[i];
}
else if((s[l-1]=='P'&&((((s[0]-48)*10)+(s[1]-48))!=12))||(s[l-1]=='A'&&((((s[0]-48)*10)+(s[1]-48))==12))){
cout<<((((s[0]-48)*10)+(s[1]-48))+12);
for(i=2;i<l-2;i++)
cout<<s[i];
}
return 0;
}
+ 1
Show code please.