0

Help - operator overloading

I am trying to apply the instructions according to the overload but it gives me an error in the output. I need help with this exercise. The problem mentions the following: You and your friend are playing a game as a team. Each player must pass 2 rounds and earn points for each of them. The given program creates two Score objects where the scores for each round are stored (passed to the constructor). Overload the + operator for the Score class to calculate the team's score for each round. Remember to use the operator keyword while overloading the operator. This is my code: https://code.sololearn.com/c7qj079Ck5H3/?ref=app

7th Jul 2021, 3:02 PM
Alex Narv√°ez
Alex Narv√°ez - avatar
5 Respuestas
+ 3
Alex Narv√°ez There should be r1.round1Score + r2.round1Score; r1.round2Score + r2.round2Score; ------- public static Score operator+(Score r1, Score r2) { int res1 = r1.round1Score + r2.round1Score; int res2 = r1.round2Score + r2.round2Score; Score res = new Score(res1, res2); return res; }
7th Jul 2021, 3:18 PM
AÕĘJ
AÕĘJ - avatar
+ 1
Alex Narv√°ez I verified your updated code and it worked fine.
7th Jul 2021, 3:31 PM
AÕĘJ
AÕĘJ - avatar
+ 1
Okay, copy the code I had here from the original one and change it and now it worked for me. Very strange but now it did work. Thank you I ŠīÄŠīć "T…™ŠīćŠīá"
7th Jul 2021, 3:52 PM
Alex Narv√°ez
Alex Narv√°ez - avatar
0
Correct, however it does not work for me in the module, I get an error even though it seems to work in the test editor. I don't know what is wrong or missing
7th Jul 2021, 3:17 PM
Alex Narv√°ez
Alex Narv√°ez - avatar
0
I ŠīÄŠīć "T…™ŠīćŠīá" I already tried, and modify the code. You can verify it, the output seems to be fine but in the exam module it goes wrong. I don't understand why it generates an error
7th Jul 2021, 3:25 PM
Alex Narv√°ez
Alex Narv√°ez - avatar