0
Could anyone tell me the reason for the wrong outputs in codecoach
16 Antworten
+ 3
Ņīñjæ
Well outputs are not wrong maybe there is some mistake in your code.
+ 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
+ 1
Ņīñjæ it shows me 1:00 for 1:15 AM
+ 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...
+ 1
Ņīñjæ
No for different inputs there is difference output.
Btw I don't know why there is 2 dislikes.
0
Abhay it showing me 1:15 AM😅
0
Ņīñjæ
Problem is in reading input. When I print str just after cin it's nothing printing.
0
I Am AJ but why i got printed🤔
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.
0
Ņīñjæ How you got printed. Just enter 11:00 PM then see how you got?
https://code.sololearn.com/cc2kteR761m7/?ref=app
0
I Am AJ ! PMPM23:00 PM I got like this
0
Abhay srry i tried that too but not working😥
0
I Am AJ ! Thk u, but is there a reason for different outputs🤔
0
I Am AJ ! No, i mean the reason others and i getting different outputs for the same input😅
0
I Am AJ ! Probably for giving the ans directly 😅😅
- 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;
}