+ 4

Now my code produced: "Time limit exceeded". What should I do to make that code work fine?

https://www.sololearn.com/discuss/1235698/?ref=app

24th Apr 2018, 5:12 PM
Kirill Kardapoltsev
Kirill Kardapoltsev - avatar
5 ответов
+ 5
I added a counter of rounds and now they are also displayed!!!😊
25th Apr 2018, 4:20 AM
Kirill Kardapoltsev
Kirill Kardapoltsev - avatar
+ 4
I fixed the code and now it works well!!!
24th Apr 2018, 5:33 PM
Kirill Kardapoltsev
Kirill Kardapoltsev - avatar
+ 2
Thank you all very much
24th Apr 2018, 5:27 PM
Kirill Kardapoltsev
Kirill Kardapoltsev - avatar
+ 1
void hit(Player obj) { obj.setHealf(obj.getHealf()-getPower()); } You are making a copy of the player here, so any changes applied to it never reflect outside the function. Therefore the hp of the player never reaches <= 0 and the while loop keeps looping. To fix it take the Player obj as a reference: void hit(Player& obj) { ... } So that changes are actually kept.
24th Apr 2018, 5:22 PM
Dennis
Dennis - avatar
+ 1
I have answered in the original discussion
24th Apr 2018, 5:26 PM
KrOW
KrOW - avatar