Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Having an issue creating this in C-Sharp C# Cant seem to fifure out how to do ma

ID: 3783986 • Letter: H

Question

Having an issue creating this in C-Sharp C#

Cant seem to fifure out how to do math in an array

After catching the returned cost Array, create one last custom function called SumOfCosts.

a. This array should accept the cost array as a parameter.

b. Inside of this function create a variable to hold the total sum of the items costs.

c. Loop through each item in the cost Array and add their total to the sum.

d. Return this sum to the Main method. Use the total sum variable that is return in a final output to the user that is in this format.

Explanation / Answer

class TestRef

{

    static void FillArray(ref int[] arr)

    {

        // Create the array on demand:

        if (arr == null)

        {

            arr = new int[10];

        }

        // Fill the array:

        arr[0] = 1111;

        arr[4] = 5555;

    }

    static void Main()

    {

        // Initialize the array:

        int[] theArray = { 1, 2, 3, 4, 5 };

        // Pass the array using ref:

        FillArray(ref theArray);

        // Display the updated array:

        System.Console.WriteLine("Array elements are:");

        for (int i = 0; i < theArray.Length; i++)

        {

            System.Console.Write(theArray[i] + " ");

        }

        // Keep the console window open in debug mode.

       System.Console.WriteLine("Press any key to exit.");

        System.Console.ReadKey();

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote