Hey guys, I'm completely lost on what to do next, I'm writing a program that takes numbers from 4 separate columns in two rows and adding those numbers at the bottom. It should look something like this...with "x" being the sum of the numbers in the columns. (Dashes are cosmetically for the forum to align right, not in actual program)
25 -------- 14 -------- 18 --------- 12
15 -------- 19 -------- 48 --------- 58
22 -------- 36 -------- 15 --------- 88
22 -------- 25 -------- 18 --------- 08
------------------------------------------------
84----------94----------99----------167
24 -------- 13 -------- 17 --------- 15
15 -------- 19 -------- 48 --------- 58
22 -------- 36 -------- 15 --------- 88
22 -------- 25 -------- 18 --------- 08
------------------------------------------------
83----------93----------98----------169
I've got the array set up right I believe I just can't figure out how to sum all the numbers without getting a goofy answer.
Thanks for any help you have!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
int const row = 4, col = 4;
void print_array(double[][col]);
void total_cols(double[][col]);
void total_rows(double[][col]);
int main()
{
double num_arr[row][col]={{4.2,5.1,6.8},{5.5,4.7,8.2},{2.7,3.9,6.5}};
print_array(num_arr);
cout << endl;
total_cols(num_arr);
print_array(num_arr);
}
void print_array(double n[][col])
{
for(int i=0;i<row-1;i++)
{
for(int j=0;j<col;j++)
cout << setw(8) << n[i][j];
cout << endl;
}
for(int k=0;k<col;k++)
cout << setw(8) << "-------";
cout << endl;
for(int j=0;j<col;j++)
cout << setw(8) << n[row-1][j];
cout << endl;
}
void total_cols(double n[][col])
{
for(int j=0;j<col;j++)
for(int i=0;i<row-1;i++)
n[row-1][j]+=n[i][j];
}
void total_rows(double n[][col])
{
// Having Problems here
}
|