Create a console-based application whose Main() method declares an array of eight integers.
Call a method to interactivelyfill the array with any number of values up to eight.
Call a second method that accepts out parameters for the arithmetic average and the sum of the values in the array.
Display the array values, the number of entered elements, and their average and sum in the Main() method.

I CAN'T DISPLAY THE SUM AND THE AVERAGE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ArrayManagement
{
    class Program
    {

        static double arrayMath(double[] myArray, out double sum, out double avg)
        {
            sum = myArray.Sum();
            avg = myArray.Average();
            Console.WriteLine("sum is: ",sum);
            return sum;


        }
        static void displayArray(double[] myArray)
        {
            Console.Write("Your numbers are: ");
            for (int i = 0; i < 8; i++)
                Console.Write(myArray[i] + " ");

            Console.WriteLine();

        }

        static double[] fillArray()
        {
            double[] myArray;
            myArray = new double[8];
            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;

        }

        static void Main(string[] args)
        {
            double[] myArray;
            myArray = new double[8];
            myArray = fillArray();
            double sum, avg;
            displayArray(myArray);
            arrayMath(myArray, out sum, out avg);

          



        }


    }
}

You also have to make your count variable on line 35 global to the Program class. The array may be filled with less than 8 elements.

Thank you very much,

i have another question for you if i can get you advice how to do it

tere is an attachment provided

how do i start

Attachments Screen_shot_2011-03-26_at_1.14_.27_PM_.png 31.58 KB

Please remember shyla, one question per thread. MArk this one as salved (vote as useful to those guys who answered on your question), and mark the whole thread as answered.!
Remember, ONE question per thread.
Bye

This article has been dead for over six months. Start a new discussion instead.