I coded this code but it doesn\'t show output also it doesn\'tcalculate winner /
ID: 3610396 • Letter: I
Question
I coded this code but it doesn't show output also it doesn'tcalculate winner
//include precompiled libraries
#include<cstdlib >
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
/*
Name :Main
PreConditions :User must enter the Votes
PostConditions :Outputs Results1
Dates of Coding :April 8, 2009 11:00 AM
Purpose1 :Show winner
Purpose2 :Show the winner andvotes and percentage
*/
//Global Variable Declaration area
int votes[20];
// function Declaration
int findMax(int votes[]);
void main()
{
//Variable Declaration Area
string name[10];
int total=0;
float percent[10];
int mtotal;
int i=1;
// inputing values
for ( i=1; i<6;i++)
{
cout<<" Please Enter the "<< i << " names ofcandidates in local election = " ;
cin>>name[i];
cout<<" Please Enter Mr/Ms " << name[i] <<" number ofvotes espectively = " ;
cin>>votes[i];
}
for (i=1; i<6; i++)
{
total=total+votes[i]; // Total Calculation
}
//Calculating Percentagevotes
for (i=1; i<6; i++)
{
percent[i]= (float) ((votes[i]/total)*100);
}
cout<<" Candidate "<<' '<<" Votes Received"<<' '<<"% of Total Votes"<< endl;
cout<<setprecision(2);
//Outputing Data
for (i=1; i<6; i++)
{
cout<<name[i]<<' '<<' '<<' '<<votes[i]<<' '<<percent[i]<<endl;
}
cout<<"Total-----"<<total<<endl;
mtotal=findMax(votes); //function Calling here
// Outputing Winner ofElection
cout<<"Winner of theelection is "<< name[mtotal]<<endl;
system("pause");
}// End of main
/*
Name :Function
Purpose1 :Calculate Winner
Purpose2 :
*/
int findMax(int votes[])
{
int i,max;
max=votes[0];
for (i=1; i<6; i++)
{
if(votes[i]>max)
max=votes[i];
}
return max;
} // End of function
Explanation / Answer
//include precompiled libraries
#include<cstdlib >
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
/*
Name :Main
PreConditions :User must enter the Votes
PostConditions :Outputs Results1
Dates of Coding :April 8, 2009 11:00 AM
Purpose1 :Show winner
Purpose2 :Show the winner and votes andpercentage
*/
//Global Variable Declaration area
int votes[20];
// functionDeclaration
int findMax(int votes[]);
void main()
{
//Variable Declaration Area
string name[10];
int total=0;
float percent[10];
int mtotal;
int i=1;
// inputing values
for ( i=1; i<6;i++)
{
cout <<" Please Enter the "<< i<< " names of candidates in local election = ";
cin>>name[i];
cout <<" Please Enter Mr/Ms " <<name[i] <<" number of votes espectively = " ;
cin>>votes[i];
}
for (i=1; i<6; i++)
{
total=total+votes[i]; // Total Calculation
}
//Calculating Percentage votes
for (i=1; i<6; i++)
{
percent[i] = (((float)votes[i]/total)*100);
}
cout <<" Candidate "<<' '<<"Votes Received" <<' '<<" % of TotalVotes"<<endl;
cout<<setprecision(2);
//Outputing Data
for (i=1;i<6; i++)
{ cout<<setprecision(2);
cout <<name[i]<<" "<<votes[i]<<" "<<percent[i]<<endl;
}
cout<<"Total-----"<<total<<endl;
mtotal=findMax(votes); // function Callinghere
// OutputingWinner of Election
cout<<"Winner of the election is "<<name[mtotal]<<endl;
system("pause");
}// End of main
/*
Name :Function
Purpose1 :Calculate Winner
Purpose2 :
*/
int findMax(intvotes[])
{
int i,max,index;
max=votes[1];
index=1;
for (i=2; i<6; i++)
{
if (votes[i]>max)
{max=votes[i];
index=i;
}
}
return index;
} // End of function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.