0

What is the problem with this program???

static double average (int x,int y,int z) { double m=(x+y+z)/3; return m; } static void Main(string [] args) { x = Convert.ToInt32(Console.ReadLine()); y = Convert.ToInt32(Console.ReadLine()); z = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(average(m)); }

16th Mar 2018, 2:53 PM
Majdy R
Majdy R - avatar
11 Answers
+ 10
You need to declare x, y, z in main method. Also, while calling the function, use average(x, y, z) since your function requires 3 parameters.
16th Mar 2018, 2:56 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 3
Why are you passing "m" to the average function? "m" is not defined in the main function but only within the scope of the function average.
16th Mar 2018, 3:16 PM
josh mizzi
josh mizzi - avatar
+ 2
static double average (int x,int y,int z) { double m=((double)(x+y+z)) /3; return m; } static void Main(string [] args) { Int x = Convert.ToInt32(Console.ReadLine()); Int y = Convert.ToInt32(Console.ReadLine()); Int z = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(average(x, y, z)); }
16th Mar 2018, 4:22 PM
josh mizzi
josh mizzi - avatar
+ 1
When dividing an integer (x + y + z) by an integer 3, rounding occurs. To avoid this, we must write m = ((double) (x+y+z)) / 3 In addition, when you call the average method, you need to specify the actual parameters, by number and type, corresponding to the list of formal parameters of the method: x, y, z
16th Mar 2018, 3:55 PM
Вадим Сухотин (Vadim Sukhotin)
Вадим Сухотин (Vadim Sukhotin) - avatar
0
sorry but cant understant any of what you said anyway thanks a lot
16th Mar 2018, 4:17 PM
Majdy R
Majdy R - avatar
0
to make me understand could you please give me the correct full program?
16th Mar 2018, 4:19 PM
Majdy R
Majdy R - avatar
0
thanks josh but it didnt work
16th Mar 2018, 4:50 PM
Majdy R
Majdy R - avatar
0
K I will test and tweak it.
16th Mar 2018, 4:51 PM
josh mizzi
josh mizzi - avatar
0
yes please
16th Mar 2018, 4:51 PM
Majdy R
Majdy R - avatar
0
Huh seen the C# Compiler isn't working
16th Mar 2018, 4:59 PM
josh mizzi
josh mizzi - avatar
0
Happened the same to me
16th Mar 2018, 5:00 PM
Majdy R
Majdy R - avatar