Still having trouble with functions calls...

nm
Last edited on
First of all your loops are wrong.The loop will also write one element on an invalid location.Change them like this:
1
2
3
4
for (column=0;column<4;column++)
{
     //code here.....
}


As for the function compute sum,can you please explain a little that what does it do?
Last edited on
Nobody is able to say "What goes here???" because your main function and your computesum function are both invalid.

At least to call computesum you should declare in the main two additional arrays for keeping sums of rows and columns. Also in computesum you should use the array passed as the first argument instead of the local array declared in the function.

So in general the call can look something as

computesum( twoarr, Array_for_sums_of_rows, Array_for_sums_of_columns );
I've made a little headway on this, but there's a couple of things I can't figure out for the life of me.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

void computesum(int arrray1 [][4], int rowsum [], int colsum []);

void main ()
{
	int row, column, num;
	int twoarr [6][4];
	int rowsum [6];
	int colsum [4];
	ifstream infile;
	ofstream outfile;

	infile.open("E:\\CFiles\\DataFile3.txt");

	cout<<fixed<<showpoint<<setprecision(2);

for (row=0;row<6;row++)
	for (column=0;column<4;column++)
		infile>>twoarr[row][column];


if (column=1)
	cout<<setw(16)<<"Fish 1| ";
 if (column=2)
	cout<<" Fish 2| ";
 if (column=3)
	 cout<< " Fish 3|";
 if (column=4)
	 cout<<"  Fish 4| ";

cout<<endl;

for (row=0;row<6;row++)
{
	cout<<"Lake "<<row+1;
	for (column=0;column<4;column++)
	{
		cout<<setw(8)<<twoarr[row][column]<<"|";
	}
	cout<<endl;
}
computesum(twoarr, rowsum, colsum);
}


void computesum(int arrray1 [][4], int rowsum [], int colsum [])
{
	ifstream infile;
	infile.open("E:\\CFiles\\DataFile3.txt");
	int row,column;
	int twoarr [6][4];
	for (row=0;row<6;row++)
	for (column=0;column<4;column++)
		infile>>twoarr[row][column];

	for (row=0;row<6;row++)
		rowsum[row]=0;
	for (row=0;row<6;row++)
		for(column=0;column<4;column++)
			rowsum[row]=rowsum[row]+array1[row][column];
	
	for (column=0;column<4;column++)
		colsum[column]=0;
	for(column=0;column<4;column++)
		for (row=0;row<6;row++)
			colsum[column]=colsum[column]+array1[row][column];

	
	for (row=0;row<6;row++)
		for(column=0;column<4;column++)
			cout<<colsum<<rowsum;
}


Everything up until line 47 works exactly like I want it to. I'm afraid I just don't understand how this function works. The syntax was provided by the instructor. I'm not sure what "int array1 [][4]" is supposed to do or how to get it to work. This function is supposed to find the sum of the rows and columns. If anyone could help me with this it would be a lifesaver.
Last edited on
Topic archived. No new replies allowed.