Add columns in array, help?

please help?!?! I have list of numbers in columns and rows. I need to add the numbers so that i get a total for each column. and each column is cout. so the answer should read out: 23,13,15,339

Also note: I'm using Xcode for mac so the only difference is i do not need "int main(gibberish)" but that should be all you can post your version if not mac and i can figure it out then.

This is what i have so far, i feel that i am almost there.

#include <iostream>
#include <fstream>

using namespace std;

#define ROWS 6
#define COLS 4

int main()
{
fstream fin;
int data[ROWS][COLS]=
{ 1,2,2,53,
1,2,1,54,
1,1,2,55,
1,3,2,55,
9,3,5,55,
10,2,3,67
};

double sumc1=0, sumc2=0, sumc3=0, sumc4=0;

for(int r = 0; r < COLS; r++)
{ for(int c = 0; c < ROWS; c++)
{
sumc1 += data[r][1];
sumc2 += data[r][2];
sumc3 += data[r][3];
sumc4 += data[r][4];
}
}
cout<<sumc1<<" , "<<sumc2<<" , "<<sumc3<<","<<sumc4;
return 0;
}
Last edited on
Topic archived. No new replies allowed.