BiDimensional Arrays HELP!

closed account (36q54iN6)
I am having problems to find out these results:

1. Row Total
2. Column Total
3.Highest in Row
4. Lowest in Row

If anyone help me I appreciate.

Here's the code:

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <cmath>
using namespace std;

const int columns = 2;
const int row = 2;
//prototipos:

//calcAvg
double calcAvg(int arreglo1[][columns], int[]);
//calcTotal
double calcTotal(int arreglo1[][columns], int[]);
//rowTotal

//highInRow

//getColumnTotal

//getHighestinRow

//getLowestInRow


int main()
{
	int arreglo1[2][2] = { {2,4},{6,8} };

	// output each array element's value                      
   for ( int row = 0; row < 2; row++ )
   {
      for ( int column = 0; column < 2; column++ )
      {
         cout << "arreglo1 [" << row << "][" << column << "]: ";
         cout << arreglo1[row][column]<< endl;
      }
   }

   //avg
	double avg;
	avg= calcAvg(arreglo1, row);
	cout<<"Array Average is: "<<avg<<endl;

	//total
	double total = 0;
	total = calcTotal(arreglo1,row);
	cout<<"Array Total is: "<<total<<endl;

	//rowTotal
	double rowTot = 0;
	rowTot = rowTotal(arreglo1,row);
	cout<<"Row Total: "<<rowTot<<endl;

	system("pause");
	return 0;

}

//calcAvg
double calcAvg(int arreglo1[][columns], int s)
{
	double a;
	double sum = 0;

	for(int i=0; i<s; i++)
	{
		for(int j=0; j<columns; j++)
		{
			sum += arreglo1[i][j];
		}
	}
	
	a = sum/(s*columns);
	
	return a;
}

//calcTotal
double calcTotal(int arreglo1[][columns], int s)
{
	
	double b;
	double sum = 0;

	for(int i=0; i<s; i++)
	{
		for(int j=0; j<columns; j++)
		{
			sum += arreglo1[i][j];
		}
	}
	
	b = sum;
	
	return b;
}


Thaks!
I am having problems to find out these results:

What kind of problems are you having?
We're not midreaders.

One obvious problem:

line 10,12,59,78: Your function declarations don't match your implementations. Your declarations state the second argument is an array, but in your implementation the second argument is a simple int.

A style issue:
line 29: You're using the same variable name for your loop variables and for your array size definition. This is not an error as the loop index will override the global constant within the scope of the loop, but is poor style because this is confusing to the reader. e.g. lines 33,34 refer to the loop variable, while lines 40,45,50 revert back to the global constant.

Last edited on
Topic archived. No new replies allowed.