0

[SOLVED] calculating wins

Hi. ive spent the last couple of days chewing over this one, im pretty sure im close, but something is missing and i cant seem to put my finger on it. im trying to do one of the challenges, but line 20 is giving me the error: "There is no argument that corresponds to the required formal parameter 'games' of 'Program.Player.GetWinRate(int,int)" https://code.sololearn.com/ca16A1036A25 you can find my current attempt here. the only thing ive changed from the original code from the challenge are the parameters in the method brackets, and the details in the method itself. The challenge reads: We are developing a profile system for players of our online game. The program already takes the number of games and wins as input and creates a player object. complete the GetWinRate() method inside the given Player class to calculate the output win rate. sample input 130 70 sample output 53 Explanation Win rate is calculated by this formula wins * 100 / games. So in this case the win rate is 70 * 100 / 130. the final result should output an integer. notice that you should execute the output of the win rate inside the method. if anyone could indicate what i could do to get this to work, id very much appreciate it. thank you!

14th May 2021, 4:59 AM
Andrew Hall
Andrew Hall - avatar
9 Respuestas
+ 3
Here is my answer: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int games = Convert.ToInt32(Console.ReadLine()); int wins = Convert.ToInt32(Console.ReadLine()); //creating the player object Player player1 = new Player(); player1.games = games; player1.wins = wins; //output player1.GetWinRate(games, wins); } } class Player { public int games; public int wins; //winrate is private private int winrate; //complete the method public void GetWinRate(int games, int wins) { int result = Convert.ToInt32((wins * 100)/games); Console.WriteLine(result); } } }
3rd Sep 2022, 1:29 PM
JOHN CADUNGOG
JOHN CADUNGOG - avatar
+ 2
no you have to just declare winrate formula by wins and games itself .no need to pass anything .then write it. just do this: winrate=wins*100/games; Console.Write(winrate);
3rd Aug 2022, 12:30 PM
PRITI KUCHHADIYA
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int games = Convert.ToInt32(Console.ReadLine()); int wins = Convert.ToInt32(Console.ReadLine()); //creating the player object Player player1 = new Player(); player1.games = games; player1.wins = wins; //output player1.GetWinRate(); } } class Player { public int games; public int wins; //winrate is private private int winrate; public int Winrate { get {return winrate;} set {winrate = value;} } //complete the method public void GetWinRate() { winrate=(wins*100/games); Console.WriteLine(winrate); } } }
30th Sep 2022, 9:01 AM
Vait Veliasi
Vait Veliasi - avatar
0
You just need to paas the arguments in the function call
14th May 2021, 5:12 AM
Geekyorion
0
bloody hell lol. so simple. thank you!
14th May 2021, 5:30 AM
Andrew Hall
Andrew Hall - avatar
0
And one more thing, don't make the argument name same as the class variables, change the argument names like gamesArg or something, in the larger programs, it may resolve a lot of issues
14th May 2021, 5:35 AM
Geekyorion
0
thanks again. ive followed your advice and changed the argument names. for anyone else doing this challenge in future, ive updated the link in my OP to show code that completes the challenge.
14th May 2021, 5:42 AM
Andrew Hall
Andrew Hall - avatar
0
Andrew Hall I tried your code (copy/paste) and I have found a bug so fixed it a bit. Here is line thst is missing, as your code was showing that winRate does not exist in current scope. public void GetWinRate(int gamesPlayed, int gamesWon) { int winRate; winRate = gamesWon * 100 / gamesPlayed ; Console.WriteLine(winRate); }
26th Apr 2023, 4:52 AM
Ivan Markovic
Ivan Markovic - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int games = Convert.ToInt32(Console.ReadLine()); int wins = Convert.ToInt32(Console.ReadLine()); //creating the player object Player player1 = new Player(); player1.games = games; player1.wins = wins; //output player1.GetWinRate(); } } class Player { public int games; public int wins; //winrate is private private int winrate; //complete the method public void GetWinRate() { Console.WriteLine((wins*100)/games); } } }
27th Jan 2024, 6:02 AM
S8ul Yuvraj
S8ul Yuvraj - avatar