Question about parallel arrays not matching up in output

I'm working on an assignment for class - I created a program that allows the user to enter data from an election and it will tell you the percent of votes each candidate got. It works, but It should be telling me who won based on the number of votes.

It isn't displaying the correct answer based on the data and I'm not really sure how to fix it. If anyone can help, that would be awesome. An output example is below 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
  #include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char** argv) {
const int CANDIDATES = 5;
int votes[CANDIDATES];
string names[CANDIDATES];
float sum=0;
float totalVotes[CANDIDATES];
int x=0;
int highest;
string highestn;


for (x=0; x<CANDIDATES; ++x)
{cout<<"Enter the name of candidate # "<<x+1<<": ";
cin>>names[x];
cout<<"Enter their number of votes: ";
cin>>votes[x];
	}	
sum = votes[0]+votes[1]+votes[2]+votes[3]+votes[4];	

	
cout<<"Candidate"<<"   "<<"Votes Received"<<"   "<<"% Of Total Votes \n";
	for (x=0; x<CANDIDATES; ++x)
{cout<<names[x]<<setw(10)<<" "<<votes[x]<<setw(10)<<" "<<(votes[x]/sum)<<"\n";
	}	
	
cout<<"Total:"<<setw(10)<<" "<<sum<<endl;

highest = votes[0];
for (x=1; x<CANDIDATES;++x)
{if (votes[x]>highest)
highest = votes[x];
highestn = names[x];
}
cout<<"The highest number of votes is "<<highest<<" so the winner is "<<highestn<<endl;

system("PAUSE");
return EXIT_SUCCESS;
}



/*Enter the name of candidate # 1: John
Enter their number of votes: 3000
Enter the name of candidate # 2: Sue
Enter their number of votes: 5000
Enter the name of candidate # 3: Bob
Enter their number of votes: 2000
Enter the name of candidate # 4: Pat
Enter their number of votes: 7000
Enter the name of candidate # 5: Jen
Enter their number of votes: 4500
Candidate Votes Received % Of Total Votes
John 3000 0.139535
Sue 5000 0.232558
Bob 2000 0.0930233
Pat 7000 0.325581
Jen 4500 0.209302
Total: 21500
The highest number of votes is 7000 so the winner is Jen
Press any key to continue . . .*/
bump
if both lines 38 and 39 should be executed if line 37 is true, then you'll want {} around the two lines. Right now only line 38 is subject to the condition. line 39 runs for each iteration of the loop.
Wow I feel like an idiot!
Anyway thank you so much! I got it working properly :)
Topic archived. No new replies allowed.