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

Discussion in 'Visual C# .Net' started by DN Admin, May 1, 2012.

  1. DN Admin

    Staff Member

    Country:
    United States
    Joined:
    Aug 7, 2010
    Location:
    Joliet, IL U.S.A.
    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:

    <pre class="prettyprint 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 = (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);
    }</pre>
    <br/>

    View the full article
     
    #1

Share This Page