+ 2

What is this error? Why am I facing it?

When I use the following code in code playground, it works but when I use it as the solution to Military Time challenge, I always encounter the error "extended character is not valid in an identifier" in line 28. https://code.sololearn.com/coBn84Dys46s/?ref=app

9th Nov 2020, 1:35 PM
Rhea Rajput
Rhea Rajput - avatar
4 Respuestas
+ 3
Rhea Rajput Change your code like this: #include <iostream> #include <string> using namespace std; int main() { string time; string s=""; //stores the hours int p;//shall store the final HH in military format string m="";//stores the ":MM" part" cout<<"Enter time in the format HH:MM AM/PM\n"; getline(cin,time); int a=time.size(); for(int y=0;y<=1;y++) s=s+time[y]; m=m+time[a-5]+time[a-4]; int n=stoi(s); if(time[a-2]=='A') { if(n==12) p=0; else p=n; } else if(time[a-2]=='P') { if(n==12) p=n; else p=n+12; } if(p<10) cout<<"0"<<p<<":"<<m; else cout<<p<<":"<<m; }
9th Nov 2020, 2:24 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 1
Rhea Rajput Your mistakes: In the challenge they mentioned two types of input. 01:15 PM is equal to 1:15 PM You made mistake on this. so I count length of input has in line 14 with a variable.
9th Nov 2020, 2:42 PM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
Mohan 333 Thanks! This worked! But can you please specify what was wrong with mine? It's working just fine on my comp and the code playground 🤔
9th Nov 2020, 2:39 PM
Rhea Rajput
Rhea Rajput - avatar
0
Mohan 333 Got it, thanks!
9th Nov 2020, 2:46 PM
Rhea Rajput
Rhea Rajput - avatar