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);

          



        }


    }
}

Recommended Answers

All 6 Replies

Line 65 and 66:

Console.WriteLine("The average is {0}", avg);
Console.WriteLine("The sum is {0}", sum);

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

This is in fact a question to be posted in a new thread.
What have you got so far?

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

where is the right place to do it ?

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.