I have to get the total votes and percent of each vote for this program.I cant figure it out!
I have attached input,but this should be output.
Johnson 5000 6.2
Miller 4000 7.75
Duffey 6000 5.16
Robinson 2500 12.4
Ashtony 1800 17.22
Adkins 3500 8.85
Walls 5500 5.63
Bills 2700 11.48
Total Votes: 31000
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
void getData(int votes[8],char names[8][20]);
void printData (int votes[8],char names[8][20],int totalVotes,float per);
int totalVotes(int votes[8]);
float percent(int totalVotes[8]);
int main()
{
int votes[8];
char names[8][20];
int totVotes;
float per;
totVotes=totalVotes(votes);
per=percent(votes);
getData(votes,names);
printData(votes,names,totVotes,per);
return 0;
}
void getData(int votes[8],char names[8][20])
{
int col=0;
int row=0;
ifstream inputFile;
//opens files
inputFile.open("input.txt");
for (row = 0; row < 8; row++)
{
inputFile>>names[row];
inputFile>>votes[row];
}
inputFile.close();
cout << "Results processed and saved in output.txt" << endl;
}
int totalVotes(int votes[8])
{
int col=1;
int sum=0;
int row=0;
for(col=0;col<1;col++)
{
sum=0;
for(row=0;row<8;row++)
sum=sum+votes[col];
}
return sum;
}
float percent(int totalVotes[8])
{
int row=0;
int sum=0;
{
for (row = 0; row < 8; row++)
{
sum=sum+totalVotes[row];
}
return sum/8.0;
}
void printData (int votes[8],char names[8][20],int totVotes,float per )
{
ofstream outputFile;
outputFile.open("output.txt");
int row;
for (row = 0; row < 8; row++)
{
outputFile<<names[row] << " ";
outputFile<<votes[row] <<" ";
outputFile<<per[row]<<endl;
}
outputFile<<"Total Votes:"<<totVotes<<endl;
outputFile.close();
}