Passing array

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
#include <iostream>
#include <iomanip>
using namespace std;
//Global declaration
int table[5][4] = { { 192,148, 1206, 137 },
{ 147, 190, 1312,121 },
{ 186, 112, 1121, 138 },
{ 114,121,1408,139 },
{ 267,113, 1382,129 },
};
int candidateSum[5];
int stationSum[4];
int voteSum( int voteArray[][4], int row, int rSum[], int cSum[]);
int main()
{
int totalSum;
cout << "This is an Election System that displays the voting results of 5 candidates at 4 polling stations."<<endl;
cout << "\nThe program is using function voteSum() to determine:" << endl;
cout << "(i) the sum of votes cast for each candidate and " << endl;
cout << "(ii)the sum of votes cast for each polling station." << endl;
//By using array table, call function voteSum to find 1) the candidates sum of votes and 2) the polling stations sum of votes; using the table array, and return the total of votes in the election.
totalSum = voteSum( table, 5, candidateSum, stationSum);
cout << "\nThe election details are shown in the following table:" << endl<<endl;

}

int voteSum(int voteArray[][4], int row, int rSum[],int cSum[])
{int total;
 total=0;
 cout<<setw(30)<<setfill(' ');
 for(int i=0; i<4 ;i++)
	cout<<"Station "<<i+1<<setw(10);
    cout<<setw(5)<<'|'<<" TOTAL VOTE";
	cout<<setfill('-')<<setw(79)<<"-"<<endl;
	for(int i=0; i<row ;i++)
	{cout<<"Candidate "<<i+1<<" : ";
      for (int j=0; j<4; j++)
	   cout<<setw(12)<<setfill(' ')<<voteArray[i][j];
	  cout<<setw(7)<<'|';
	  {
      for (int j=0; j<4; j++)
	   rSum[i]+=voteArray[i][j];
	  cout<<setw(10)<<rSum[i];}
	  cout<<endl;}
	cout<<setfill('-')<<setw(79)<<"-"<<endl;
	cout<<"TOTALS      : ";
	for (int j=0; j<4; j++)
	{
		for(int i=0; i<row ;i++)
		cSum[j]+=voteArray[i][j];
	cout<<setw(12)<<setfill(' ')<<cSum[j];
	   for(int i=0; i<row ;i++)
		   total +=voteArray[i][j];}
	cout<<setw(7)<<'|';
	cout<<setw(10)<<total<<endl;
	 
	  return total;
}


Hi guys,I'm trying to pass my output to main instead below this line,cout << "\nThe election details are shown in the following table:"

Is there anything I can do?Thanks in advanced.
What do you mean by "pass output"? What output? The total number of votes? The strings your are sending to cout?
What is the problem you are currently encountering? we require something to work off in order to help you.
Sorry,let me rephrase as I typed it in a hurry.
int voteSum(int voteArray[][4], int row, int rSum[],int cSum[])

The above code is called in the main,line 22 resulting an output.Is there a way for me to change the cout in int voteSum(int voteArray[][4], int row, int rSum[],int cSum[])

to main so that I can display the data below line 23?

Thanks in advanced.

Last edited on
Topic archived. No new replies allowed.