I can't align the output of my program.
I want to keep the same names and get the right spacing.
The code is provided below.
I also tried using left
but it still does not work.
The output I am expecting:
The output I am getting:
//taking name and votes recieved
for (i = 0; i < 5; i++)
{
cout << "Enter last name of candidate " << (i + 1) << ": ";
cin >> names[i];
cout << "Enter votes recived by " << names[i] << ": ";
cin >> votes[i];
}
//calculating total votes
for ( i = 0; i < 5; i++)
{
total = total + votes[i];
}
//calculating percentage of total votes for each candidate
for ( i = 0; i < 5; i++)
{
percent_of_total[i] = (votes[i] / total) * 100.0;
}
//checking winner
winner = names[0];
int most = 0;
for ( i = 0; i < 5; i++)
{
if (votes[i] > most)
{
most = votes[i];
winner = names[i];
}
}
cout << fixed << setprecision(2);
//dislaying
cout << "Candidte" << setw(20) << "Votes Recieved" << setw(20) << "% of Total Votes";
for (i = 0; i < 5; i++)
{
cout << endl;
cout << names[i] << setw(20) << votes[i] << setw(20) << percent_of_total[i];
}
cout << endl;
cout << "Total" << setw(20) << total;
cout << endl << "The winner of the Election is " << winner << ".";
return 0;
}