Could anyone tell me the reason for the wrong outputs in codecoach | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Could anyone tell me the reason for the wrong outputs in codecoach

https://code.sololearn.com/c396Ufuu9x8s/?ref=app

3rd Feb 2021, 3:14 PM
Noice
Noice - avatar
16 Answers
+ 3
Ņīñjæ Well outputs are not wrong maybe there is some mistake in your code.
3rd Feb 2021, 3:17 PM
A͢J
A͢J - avatar
+ 3
It ouputs 12:00 for 12:00 AM and 12:00 for 12:15 AM , but it should output 00:00 and 00:15 , i might be wrong on 12:00 AM and even for 1:15 AM it outputs 1:00 , so there are plenty of things you need to do right
3rd Feb 2021, 3:19 PM
Abhay
Abhay - avatar
+ 1
Ņīñjæ it shows me 1:00 for 1:15 AM
3rd Feb 2021, 3:26 PM
Abhay
Abhay - avatar
+ 1
I know the bug I also faced 8 when I solve this code coach challenge The bag is that when we convert a time of 1 digit we have to add 0 before it. Like to convert 1:00 a.m. to military time, your output should be 01:00...
3rd Feb 2021, 4:14 PM
Abhay
Abhay - avatar
+ 1
Ņīñjæ No for different inputs there is difference output. Btw I don't know why there is 2 dislikes.
7th Feb 2021, 5:13 AM
A͢J
A͢J - avatar
0
Abhay it showing me 1:15 AM😅
3rd Feb 2021, 3:25 PM
Noice
Noice - avatar
0
Ņīñjæ Problem is in reading input. When I print str just after cin it's nothing printing.
3rd Feb 2021, 3:27 PM
A͢J
A͢J - avatar
0
I Am AJ but why i got printed🤔
3rd Feb 2021, 3:31 PM
Noice
Noice - avatar
0
Ņīñjæ Read input like this. There is colon (:) also. cin >> hours >> colon >> minutes >> str; when I did like this I got 3 test case passed.
3rd Feb 2021, 3:46 PM
A͢J
A͢J - avatar
0
Ņīñjæ How you got printed. Just enter 11:00 PM then see how you got? https://code.sololearn.com/cc2kteR761m7/?ref=app
3rd Feb 2021, 3:49 PM
A͢J
A͢J - avatar
0
I Am AJ ! PMPM23:00 PM I got like this
3rd Feb 2021, 3:56 PM
Noice
Noice - avatar
0
Abhay srry i tried that too but not working😥
3rd Feb 2021, 4:46 PM
Noice
Noice - avatar
0
I Am AJ ! Thk u, but is there a reason for different outputs🤔
7th Feb 2021, 5:10 AM
Noice
Noice - avatar
0
I Am AJ ! No, i mean the reason others and i getting different outputs for the same input😅
7th Feb 2021, 5:14 AM
Noice
Noice - avatar
0
I Am AJ ! Probably for giving the ans directly 😅😅
7th Feb 2021, 8:13 AM
Noice
Noice - avatar
- 2
Ņīñjæ Solved you can try it #include <iostream> #include <string> using namespace std; class MilTime { int hours,minutes; string str; char colon; string time; public: void gettime(void) { cin >> hours >> colon >> minutes >> str; } void converter(void) { if (hours == 12 && str == "PM") time = to_string(hours); if (hours == 0 && str == "AM") time = "00"; else if(hours > 0 && hours < 12 && str == "PM") time = to_string(hours + 12); else if(hours > 0 && hours < 12 && str == "AM") { if (hours >= 11) time = to_string(hours); else time = "0" + to_string(hours); } } void display(void) { cout << time << ":"; printf("%.2d", minutes); } }; int main() { MilTime a; a.gettime(); a.converter(); a.display(); return 0; }
3rd Feb 2021, 4:59 PM
A͢J
A͢J - avatar