Jan 24, 2016 at 6:45pm UTC
#include <iostream>
#include <iomanip>
using namespace std;
const int SIZE = 5;
string getName (string message);
int getValue (string message);
double getsum (int votes[]);
double getAve (int votes[], double average[]);
void printArray (int votes[], string name[], double Average[]);
int win (int votes[], string name[]);
int count;
int main()
{
int votes[SIZE];
string lastName[SIZE], winner;
double average[SIZE];
for (count = 0; count < SIZE; count++)
{
lastName[count] = getName ("Enter Last Name: ");
votes[count] = getValue ("Enter Votes Recieved: ");
}
getAve (votes,average);
printArray (votes,lastName,average);
cout << "\nTOTAL: " << getsum (votes);
winner = win (votes, lastName);
cout << endl;
system("Pause");
return 0;
}
string getName (string message)
{
string name;
cout << message;
cin >> name;
return name;
}
int getValue (string message)
{
int value;
cout << message;
cin >> value;
return value;
}
double getsum (int votes[])
{
int sum;
sum = 0;
for (count = 0; count < SIZE; count++)
sum = sum + votes[count];
return sum;
}
double getAve (int votes[], double average[])
{
for (count = 0; count < SIZE; count++)
average[count] = (votes[count] / getsum(votes)) *100;
return average[count];
}
void printArray (int votes[], string name[], double Average[])
{
system("cls");
cout<< "CANDIDATE " << setw(15) << "VOTES RECIEVED " << setw(15) << "% OF TOTAL VOTES" << endl;
for (count = 0; count < SIZE; count++)
cout << endl << name[count] << setw(15) << votes[count] << setw(25) << Average[count] << endl;
}
int win (int votes[], string name[])
{
int win;
win = votes[0];
string winner;
for (count = 0; count < SIZE; count++)
{
if (votes[count] > win)
{
win = votes[count];
winner = name[count];
}
}
cout << "\nWINNER IS: " << winner;
}
THE FIRST OUTPUT IN THE % OF TOTAL VOTES IS CORRECT BUT THE NEXT OUTPUT IS WRONG, IT GIVES ME RANDOM NUMBERS! PLEASE HELP!
Jan 24, 2016 at 7:17pm UTC
Please update your post and use code tags -
http://www.cplusplus.com/articles/jEywvCM9/
And explain your problem. What is not working (what line of code), What is happening and what are you expecting?
Edit: Also a tip. Next time come up with a title that describes your problem. HELP ME!!!! is just worthless. Another tip is to put the explanation of what your problem is and all of that before the code, so we can read it first.
http://www.cplusplus.com/forum/beginner/1/
Last edited on Jan 24, 2016 at 8:10pm UTC