-1

I'm a beginner, and I'm taking a long time to figure this out. I want to be able to add and find the average of the array the user has created.

I have added the code I have written so far, and I don´t know if there's some easy way to do it or to add a for? Have no clue and was hoping I could get some pointers.

Thanks in advance

Console.WriteLine("how many numbers do you want to store?:");//Preguntar
int count = int.Parse(Console.ReadLine());//capturar tamaño

// Crear vector con tamaño que se ha asignado
string[] numeros = new string[count];

// Llenarlo
for (int i = 0; i < count; i++)
{
    Console.Write("Numero {0}: ", i);
    numeros[i] = Console.ReadLine();
}

// Imprimirlo
Console.WriteLine("\nvalues in vector:\n");

for (int i = 0; i < count; i++)
{
    Console.WriteLine("Posicion {0}: {1}", i, numeros[i]);
}
Lennart
  • 9,657
  • 16
  • 68
  • 84
Juan Rios
  • 29
  • 6
  • See the marked duplicate. The only thing you still need to do is parse *all* your input into `int` values (you currently only do this on line 2). – Igor Sep 12 '18 at 20:24

1 Answers1

0
        int count = 0;
        List<int> numeros = new List<int>();

        Console.Write("How many numbers?: ");
        int.TryParse(Console.ReadLine(), out count);

        for(int i = 1; i < count + 1; i++)
        {
            Console.Write("Numero {0}: ", i);
            numeros.Add(Convert.ToInt32(Console.ReadLine()));
        }

        int sum = 0;
        foreach(var i in numeros)
        {
            sum += i;
        }
        int average = sum / numeros.Count;
        Console.WriteLine(average);
William.Avery
  • 60
  • 1
  • 7