Hello,
I'm trying to make the following function:
- it takes a number n (Console.ReadLine) which defines the amount of numbers we want to add.
- it asks n times the number we want to add to the list
- it gives the average of the entered numbers.
Any ideas ?
I'm trying to make the following function:
- it takes a number n (Console.ReadLine) which defines the amount of numbers we want to add.
- it asks n times the number we want to add to the list
- it gives the average of the entered numbers.
static int Fonc_question(int n) // This function asks the questions
{
int[] questions = new int[n];
int q = n;
int r = n;
int i=0;
int res =0;
while (n > 0)
{
q -= 1;
Console.WriteLine("Nombre "+ (n) + ":");
questions[(n-(q-1))] = Convert.ToInt32(Console.ReadLine());
n=n-1;
}
if (n <= 0)
{
while (r > 0) // I'm having troubles here in order to get all the numbers I've entered so that i may do a sum of them and then divide them.
{
res +=r;
r = r - 1;
}
Console.Writeline(res/n);
}
Console.ReadLine();
return n;
}
static void Main(string[] args)
{
int nombre;
Console.WriteLine("Combien de nombres ?"); // How many numbers ?
nombre = Convert.ToInt32(Console.ReadLine());
Fonc_question(nombre);
}
Any ideas ?