Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How could I implement a loop to add values of my array; rather than add them manually? (Cant think outside the box)

$
0
0

Basically I will have more methods that will all use "num2" thats why I used the HoldArray to clean up the Main Method...

So basically in the Max method I want to use some kind of loop to add all of the "storeMax" indexes to gather rather than do it all manually, but I dont know how that possible? Please help me free my brain from thinking "inside the box" Here is the code:

public static void HoldArray(double[,] Data)
        {
            Max(Data);
        }

        static void Main(string[] args)
        {
            double[,] num2 = new double[7, 2] { { 61.1, 81.1 }, { 62.2, 82.2 }, { 63.3, 83.3 }, { 64.4, 84.4 }, { 65.5, 85.5 }, { 66.6, 86.6 }, { 67.7, 87.7 } };
            HoldArray(num2);
            Console.ReadLine();
        }

        public static void Max(double[,] Data)
        {
            double[] storeMax = new double[7]; //stores all highvalues in a single dimensional array//
            
            for (int i = 0; i < 7; i++) //this loop puts all high values of Data(num2↑) into storemax//
            {
                storeMax[i] = (Data[i, 1]);
                //put/populate all of data(num2) [i(global 0,1,2,3,4,5,6,7), index1's(high temps)] into storeMax//
            }
            double average = ((storeMax[0] + storeMax[1] + storeMax[2] + storeMax[3] + storeMax[4] + storeMax[5] + storeMax[6]) /7);
            Console.WriteLine(average);
        }


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>