+ 4
Now my code produced: "Time limit exceeded". What should I do to make that code work fine?
5 odpowiedzi
+ 5
I added a counter of rounds and now they are also displayed!!!😊
+ 4
I fixed the code and now it works well!!!
+ 2
Thank you all very much
+ 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.
+ 1
I have answered in the original discussion