Hey guys, I have this easy program and my algorithm looks right for the percentages, but I keep printing zeros. Can someone tell me what I'm doing wrong?
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main()
{
int xxx;
int total, *p;
string name, *n;
cout<<"Enter the number of total candidates: "<<endl;
cin>>total;
n = new string[total];
p = newint[total];
cout<<"\nEnter the names of the candidates followed by the votes: "<<endl;
for(int i = 0; i < total; i++)
{
cin>>n[i];
cin>>p[i];
}
cout<<fixed<<showpoint<<setprecision(2)<<endl;
int totalVotes = 0;
for(int c = 0; c < total; c++)
totalVotes = totalVotes + p[c];
cout<<"Candidate Votes Received % of Total Votes"<<endl;
double percent;
for(int z = 0; z < total; z++)
{
percent = (p[z] / totalVotes) * 100;
cout<<left<<setw(22)<<n[z]<<setw(22)<<p[z]<<percent<<endl;
}
cout<<"Total "<<totalVotes<<endl<<endl;
int maxIndex = 0;
int index;
for(index = 1; index < total; index++)
if(p[maxIndex] < p[index])
maxIndex = index;
cout<<"\nThe winner of the election is "<<n[maxIndex]<<"."<<endl;
cin>>xxx; // read output
return 0;
}