0

How do I make an array to find the largest portion of another array?

I am trying to find the candidate that received the largest amount of votes from the following file:

Johnson 5000

Miller 4000

Duffy 6000

Robinson 2500

Ashtony 1800

here is my code:

```
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
string candidates[6];
double votes[6];
double sum = 0.0;
ifstream inFile("candidates.txt");
for ( int i = 0; i < 6; ++i )
{
if ( inFile >> candidates[i] >> votes[i] )
{
sum = sum + votes[i];
}
else
{
break;
}
}
cout << endl;
cout << "Candidate Votes % of Total" << endl;
cout << setprecision(0) << candidates[0] << setw(5) << "\t" << votes[0]
<< setw(15) << setprecision(4) << ((votes[0] / sum) * 100) << endl;
cout << setprecision(0) << candidates[1] << setw(5) << "\t" << votes[1]
<< setw(15) << setprecision(4)<< ((votes[1] / sum) * 100) << endl;
cout << setprecision(0) << candidates[2] << setw(5) << "\t" << votes[2]
<< setw(15) << setprecision(4)<< ((votes[2] / sum) * 100) << endl;
cout << setprecision(0) << candidates[3] << setw(5) << "\t" << votes[3]
<< setw(15) << setprecision(4)<< ((votes[3] / sum) * 100) << endl;
cout << setprecision(0) << candidates[4] << setw(5) << "\t" << votes[4]
<< setw(15) << setprecision(3) << ((votes[4] / sum) * 100) << endl;
cout << "\n" << endl;
cout << setprecision(0) << "Total " << setw(5) << "\t" << sum
<< "\n" << endl;
}
```