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
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.
+ 2
Ive solve it myself ,ty