Help...(solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help...(solved)

We are developing a profile system for online game players. The program already takes the number of games and wins as input and creates a player object End the GetWinRate () function in this Player class to calculate and output the win rate. Sample input 130 70 Result example 53 Explanation The win rate is calculated using the following formula: number of wins * 100 / number of games. Therefore, in this case, the winning coefficient will be 70 * 100/130 = 53 (the result must be an integer). I just dont understand how i can do this,i ve tried a lot of ways but its always error, im so dumb( https://code.sololearn.com/c0Oy8nc822d4/?ref=app

7th Mar 2021, 8:40 AM
Nazik Sidorchuk
Nazik Sidorchuk - avatar
2 Answers
+ 4
This might help you, public void GetWinRate() { winrate=(int)((float)wins/games*100); Console.WriteLine(winrate); } int/int always results in int so 70/130 was returning 0.53 which got converted to 0 . making one of them float yields in a floating number, 0.53 and divided by 100 gives 53.__ but again we need to type cast it to int as we assign the value to an int variable.
7th Mar 2021, 8:51 AM
Abhay
Abhay - avatar
+ 2
Ive solve it myself ,ty
7th Mar 2021, 6:13 PM
Nazik Sidorchuk
Nazik Sidorchuk - avatar