To help your class you are going to write a program that allows
the user to enter the last names of the five candidates who ran
for class president. the user will also enter how many votes each
candidate received and then output each candidates last name, how
many votes he/she received, and the percentage of the total votes
received by the candidate. In addition, your program will output
the winner of the elcetion.
For example:
Candidate Votes Received % of Total Votes
Smith 110 24.45
Jameson 35 7.78
Thomason 150 33.33
Evans 65 14.44
Bloom 90 20.00
Total 450
The New Class President is Thomason.
Help/Suggestions? Code is what I did so far in class. Most of the bottom is just a joke i'm not sure what the hell i'm doing.
the user to enter the last names of the five candidates who ran
for class president. the user will also enter how many votes each
candidate received and then output each candidates last name, how
many votes he/she received, and the percentage of the total votes
received by the candidate. In addition, your program will output
the winner of the elcetion.
For example:
Candidate Votes Received % of Total Votes
Smith 110 24.45
Jameson 35 7.78
Thomason 150 33.33
Evans 65 14.44
Bloom 90 20.00
Total 450
The New Class President is Thomason.
Code:
// main.cpp : Class President Election
#include <iostream>
#include <string>
using namespace std;
int main()
{
double votes [5];
double percent;
string lName[5];
string names;
double avotes;
int i;
double sum=0;
int index;
int maxIndex;
for (i=0; i<5; i++)
{
cout<<"Enter the last name of a candidate: ";
cin>>lName[i];
cout<<endl;
cout<<"Enter how many votes they received: ";
cin>>votes[i];
cout<<endl;
sum=sum+votes[i];
}
cout<<"Candidate\tVotes Received\t\t% of Total Votes"<<endl;
for (index=0; index<5; index++)
cout<<votes[index] <<"\t"<<votes[index];
cout<<"The total number of votes is "<<sum<<"";
cout<<endl;
//string winna;
//winna=votes[maxIndex];
//maxIndex=0;
//for (index=1; index<5; index++)
//if (votes[maxIndex] < votes[index])
//maxIndex=index;
//cout<<"The New Class President is: "<<winna<<"";
//cout<<endl;
for (index=0; index<10; index++)
cout<<votes[index] <<"\t"<<votes[index];
return 0;
}
Help/Suggestions? Code is what I did so far in class. Most of the bottom is just a joke i'm not sure what the hell i'm doing.

Comment