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)); }
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.
+ 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.
+ 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));
}
+ 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
0
sorry but cant understant any of what you said
anyway thanks a lot
0
to make me understand
could you please give me the correct full program?
0
thanks josh but it didnt work
0
K I will test and tweak it.
0
yes please
0
Huh seen the C# Compiler isn't working
0
Happened the same to me