Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
input text file:

<br />
Lincoln 120 300 400<br />
Parks 100 500 250<br />
Shakespeare 0 30 50<br />
Ghandi 250 100 40<br />
Ashe 300 50 175<br />
Rodriguez 87 118 320<br />
Curie 284 0 112<br />


goes into this function
<br />
void displayResults(int list[][COL_SIZE],string nameList[])<br />
{<br />
<br />
	// this will be a function to calcualte percentage of all the calculations<br />
	double percenttotal = 0;<br />
	int num = 0,votenum = 0;<br />
	double perc = 0;<br />
	string n;<br />
	cout << "Results in sorted order" << endl;<br />
	cout << "Name            Votes % Total  " << endl;<br />
	cout << "-----------     ------  ------" << endl;<br />
	for (int c = 0; c < COL_SIZE;c++)<br />
	{<br />
		cout << nameList[c] << '\t' << '\t';<br />
		votenum = 0;<br />
		//this will display the names to the left <br />
		for (int r = 0; r < ROW_SIZE - 1; r++)<br />
		{<br />
			//this adds the precinct to the right ROW totals<br />
			votenum = votenum + list[r][c];<br />
		}<br />
		percenttotal = votenum / 100.0;<br />
		cout << votenum <<"\t"<< percenttotal <<"%"<< endl;<br />
	}<br />
	cout << "----------------------------------------------" << endl;<br />
}


and this should be the OutPut:

<br />
Results in sorted order<br />
Name               Votes % of Total<br />
-----------        ----- ----------<br />
Parks               850    23.7%<br />
Lincoln             820    22.9%<br />
Ashe                525    14.6%<br />
Rodriguez           525    14.6%<br />
Curie               396    11.0%<br />
Ghandi              390    10.9%<br />
Shakespeare          80     2.2%<br />


But its not i have no idea how to sort the names and link them to the totals that are already sorted in descending order in the array
Posted
Updated 1-Dec-09 20:01pm
v3

Your goal is simply accomplished if you sort both the results array (i.e. list) and the names one (nameList) in the same function.
A better design would tie name and results together in a struct (or class).
:)
 
Share this answer
 
I am not that far in my programming class to know how to do that
i asked my teacher and he told me to ask the web forums if i had questions lol
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900