I have been working on this all day can someone please tell me what I am doing wrong.

using System;
public class ArrayManagement
{
    public static void Main(string[] args)
    {
        int[] myArray;
        myArray = new int[7];
        myArray = fillArray();
        int sum, avg;
        arrayMath(myArray, out sum, out avg);
        displayArray(myArray);
    }
    public static void arrayMath(int[] myArray, out int sum, out int avg)
    {
        sum = myArray.Sum();
        avg = myArray.Average();
    }
   public static void displayArray(int[] myArray)
    {
        Console.Write("Your sum and average is: ");
        for (int i = 0; i < 8; i++)
            Console.Write(myArray[i] + " ");
        Console.WriteLine();

    }
   public static int[] fillArray()
    {
        int[] myArray;
        myArray = new int[7];
        int count = 0;
        do
        {
            Console.Write("Please enter a number to add to the array or \"x\" to stop: ");
            string consoleInput = Console.ReadLine();
            if (consoleInput == "x")
            {
                return myArray;
            }
            else
            {
                myArray[count] = Convert.ToInt32(consoleInput);
                ++count;
            }

        } while (count < 8);
       return myArray;
        }
    }

Recommended Answers

All 2 Replies

If we knew what your were trying to achieve and what you are having problems with, we might be more inclined to help.
Also, put your code between [ CODE ] tags

I made just enough adjustments to make it compile and run without crashing.
There are some design adjustments you will need to make:

using System;
using System.Linq;

public class ArrayManagement
{
   public static void Main(string[] args)
   {
      int[] myArray;
      myArray = new int[7];
      myArray = fillArray();
      int sum, avg;
      arrayMath(myArray, out sum, out avg);
      displayArray(myArray);
   }

   public static void arrayMath(int[] myArray, out int sum, out int avg)
   {
      sum = myArray.Sum();
      avg = (int)myArray.Average();
   }
   public static void displayArray(int[] myArray)
   {
      Console.Write("Your sum and average is: ");
      for (int i = 0; i < myArray.Count(); i++)
         Console.Write(myArray[i] + " ");
      Console.WriteLine();

   }
   public static int[] fillArray()
   {
      int[] myArray;
      myArray = new int[7];
      int count = 0;
      do
      {
         Console.Write("Please enter a number to add to the array or \"x\" to stop: ");
         string consoleInput = Console.ReadLine();
         if (consoleInput == "x")
         {
            return myArray;
         }
         else
         {
            myArray[count] = Convert.ToInt32(consoleInput);
            ++count;
         }

      } while (count < 8);
      return myArray;
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.