In: Computer Science
Write in C++
Write a program that accepts the names of three political parties and the number of votes each received in the last mayoral election. Display the percentage of the vote each party received. Be sure to provide labels (party name) and number-align your output values.
ANSWER:-
#include <iostream>
using namespace std;
int main() {
string a,b,c;
int x,y,z;
cout<<"enter first party name and votes :
";
cin>>a>>x;
cout<<"enter second party name and votes :
";
cin>>b>>y;
cout<<"enter third party name and votes :
";
cin>>c>>z;
int total=x+y+z;
float per_a=(float)(x*100)/total;
float per_b=(float)(y*100)/total;
float per_c=(float)(z*100)/total;
cout<<"party name vote %"<<endl;
cout<<a<<"
"<<per_a<<endl;
cout<<b<<"
"<<per_b<<endl;
cout<<c<<" "<<per_c;
return 0;
}
OUTPUT :
// If any doubt please comment