ok, so I'm supposed to write a program which allows the user to input 5 candidate names and the number of votes they receive. The program should the spit out the names, number of votes, percentage of votes received, the total votes, and the winner of the election. This is the code:
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int totalVote(int votes[]);
int win_index(int votes[], int);
int main()
{
string candidate[5];
int votes[5];
int total, j, win;
cout<<"Please enter the candidate and the number of votes they received."<<endl;
for (j=0; j<5; j++)
{
cin>> candidate[j]>> votes[j];
}
cout<<setw(20)<<left<<"Candidate"<<setw(20)<<"Votes Received"<<setw(20)<<"% of Total Votes"<<endl;
cout<<"---------------------------------------------------------"<<endl<<endl;
total= totalVote(votes);
for (j=0; j<5; j++)
{
cout<<setw(20)<<left<<candidate[j]<<setw(20)<<votes[j]<<setw(20)<<(static_cast<float>(votes[j])/total)*100<<endl;
}
cout<<"Total Votes: "<<total<<endl;
win = win_index (votes, 5);
cout<<"The winner is: "<<candidate[win]<<endl;
return 0;
}
int totalVote(int votes[])
{
int i, total;
total=0;
for (i=0; i<5; i++)
{
total=total+votes[i];
}
return total;
}
int win_index(int votes[], int)
{
int i, j, win;
i=0;
for (j=0; j<5; j++)
{
if (votes[j]<i)
win= i;
else
win= votes[j];
}
return win;
}
The compiler is telling me that: error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >.
Does anyody know what this means?
Also, I don't think the last function is quite right... any suggestions?
Thanks