0

[C++] Issue with my average fonction...

hello everyone, I share my mini games from my computer( one of my first code, translated from french) because i have a issue with my average fonction (step 4) and the score on the second play. i try to convert a average score of victory to a percentage but on the second victory, my "for" loop a another time and cause issue: expected result : 100% result : 150% clue: one of my variable (averageWin if i remember correctly ) in average fonction become a 3,5 https://code.sololearn.com/c1w86e5FQIKA/?ref=app

12th Apr 2017, 9:35 PM
BloodyXShini
BloodyXShini - avatar
3 Réponses
+ 2
After the first win, scoreWin is { 1.0 }. The loop executes once, and averageWin is now (averageWin + 1.0) / 1 = 1.0. So, you get 100%. After the second win, scoreWin is { 1.0, 1.0 }. The loop executes twice, and averageWin is now (averageWin + 1.0 + 1.0) / 2 = 1.5. So, you get 150%. As you can see, Nofel's suggestion is correct: You need to reset averageWin back to 0.0 at the start of every new game.
13th Apr 2017, 4:14 AM
Squidy
Squidy - avatar
+ 1
maybe you should reset your averagewin variable too?
12th Apr 2017, 9:47 PM
Nofel Tiani
Nofel Tiani - avatar
0
i am late but thanks you for your help ! , it look corrected \o/ , with your explanation squidy i understands now :)
26th Apr 2017, 7:32 PM
BloodyXShini
BloodyXShini - avatar