Have patience as I am a beginner at this.I have completeed my 2d Array and have displayed its contents successfully. At the end of my program I want to total column 1 and 2 ([0],[1]) and eventually average it, but my code is not giving me the correct math(see input below). I think my operators must be wrong. Below is my code, and as I said everything is good except for the math in the last part. Look at my last for statement. Also I am using Visual studio 2008. ANY help is certainly appreciated.

my input into Array:

40  20
41  21
42  22
43  23
44  24
45  25
46  26

total for col 1 should be 301, but I am getting 602!?!

#include "stdafx.h"
#include "iostream"
#include "iomanip"
#include "cmath"
#include "string"

using namespace std;


int main ()
{
    //declare and intilize array
    int tempav[7][2]= {0};
    int tot = 0;
    int average = 0;

    //enter data into array

    for(int day = 0; day < 7; day ++)
        for (int temps = 0; temps < 2; temps ++)
    {

        cout<<"Day Number "<<day +1 << ", Temperature " << temps + 1 << ": ";
        cin>> tempav[day][temps];

    }//end for

//end for

    //display contents of array
        for (int day = 0; day < 7; day ++)
        {
            cout << "Day " << day + 1 << ": " << endl;
            for (int temps = 0; temps < 2; temps ++)
            {
                cout << " Temperature " << temps + 1 << ": ";
                cout << tempav[day][temps] << endl;
            }//end for
}//end for

              for (int day = 0; day < 7; day += 1)
        for (int temps = 0; temps < 2; temps += 1)
            tot += tempav[day][0];              
        {
            cout << " Total Col 1 " << tot << endl;

        }


    system("pause");
    return 0;
}//end of main function

You adding it twice here :

for (int day = 0; day < 7; day += 1)
for (int temps = 0; temps < 2; temps += 1)
tot += tempav[day][0]; 
{
cout << " Total Col 1 " << tot << endl;

}

just do this:

for (int day = 0; day < 7; day += 1){
 tot += tempav[day][0]; 
}

Thanks you helped me tremendously!

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.