0

I'm not able to initialize value to "hh", Can anyone help??

/* take input like this "07:05:45AM" keep in mind AM and PM should be "CAPITAL" */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { int hh, mm, ss; char t12[2]; scanf("%d:%d:%d%s", &hh, &mm, &ss, t12); if(strcmp(t12, "PM") == 0) { hh += 12; } else if(strcmp(t12, "AM") == 0) { hh = 0; } printf("%02d:%02d:%02d", hh, mm, ss); return 0; }

7th Apr 2020, 6:59 AM
Somya Sarathi Samal
Somya Sarathi Samal - avatar
4 odpowiedzi
+ 1
If your trying in here SL playground, scanf don't work in in cpp unless you have cin used.. Try in c or make using c++ code..
7th Apr 2020, 7:22 AM
Jayakrishna 🇮🇳
+ 1
In other compilers, am not sure but in scanf, it won't output from scanf so remove : from scanf, and give some spaces like scanf("%d %d %d %s", &hh, &mm, &ss, t12);
7th Apr 2020, 7:41 AM
Jayakrishna 🇮🇳
0
I'm just asking in general not in reference of sololearn
7th Apr 2020, 7:35 AM
Somya Sarathi Samal
Somya Sarathi Samal - avatar
0
Take the null character into account as well, "AM" and "PM" both require 3 characters, not 2.
7th Apr 2020, 7:49 AM
Dennis
Dennis - avatar