Hi tdeyoung,
I am new here and to C++ as well
I looked at your code and found this works for me
Code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void percentOfVotes (string *candidate, int arraySize, double *votes, double *percent, double sum);
void maxVotes (int arraySize, string *candidate, double *votes);
int main()
{
string *candidate; //the * takes the place of the array bracket on the end
int arraySize; //which makes it a pointer. Pointers are arrays and arrays are pointers.
double *votes;
double sum = 0;
double *percent;
cout << "Please enter the Number of Candidates. ";
cin >> arraySize;
cout << endl;
candidate = new string[arraySize]; //builds the array we asked for
votes = new double[arraySize]; //assigns the arraySize we asked for to our variables.
percent = new double[arraySize];
for (int index = 0; index < arraySize; index++)
{
cout << "Enter the Fisrt Name of the Candidate: ";
cin >> candidate[index];
cout << "Enter the Votes " << candidate[index] << " " << "received: ";
cin >> votes[index];
sum = sum + votes[index];
cout << endl;
}
percentOfVotes(candidate, arraySize, votes, percent, sum);
maxVotes (arraySize, candidate, votes);
return 0;
}
void percentOfVotes (string *candidate, int arraySize, double *votes, double *percent, double sum)
{
for (int index = 0; index < arraySize; index++)
{
percent[index] = ((votes[index] / sum) * 100);
cout << fixed << showpoint << setprecision(2);
cout << candidate[index] << " " << votes[index] << " ";
cout << "% Received " << percent[index] << endl;
}
}
void maxVotes (int arraySize, string *candidate, double *votes)
{
int maxIndex = 0;
double maxVotes;
for (int index = 0; index < arraySize; index++)
{
if (votes[maxIndex] < votes[index])
maxIndex = index;
maxVotes = votes[maxIndex];
}
cout << "The Winner of the Election is: " << candidate[maxIndex] << " with " << votes[maxIndex] << " votes" << endl;
}
The only change i have made is in the maxVotes routine
This is my first time helping some one so i hope i have got it correct
Thor