السلام عليكم ورحمة الله وبركاته
Write c++ program that allos the user to enter the last names of five candidates in a local election and the number of votes received
by each candidate.
the program should then output each candidtae's name, the number of votes recived, and the percentage of the total votes recived by the candidates
Your program should also output the winner of the election.
Asample output is :
Candidate Votes Recived % of Total votes
Saadi 5000 25.91
Djaballah 4000 20.72
Boutef 6000 31.09
Ali 2500 12.95
Chorfi 1800 9.33
-------
100%
the winner is Boutef
this is my try
#include <iostream.h>
#include <string.h>
#include<conio.h>
class candidate
{
private:
char name[10];
int voicesNO;
public :
void get_name();
void get_voicesNO();
char* set_name();
int set_voicesNO();
};
void candidate::get_name()
{
cout<<"Enter the name : ";
cin>>name;
}
void candidate ::get_voicesNO()
{
cout<<"Enter the no of voices: ";
cin>>voicesNO;
}
char* candidate:: set_name()
{
return name;
}
int candidate::set_voicesNO()
{
return voicesNO;
}
void main()
{ clrscr();
candidate c[5];
int sum,i,total;
for (i=0;i<5; i++)
{
c.get_name();
c.get_voicesNO();
sum = sum + c.set_voicesNO();
}
cout<<"\n------------------------------------------------------------------";
cout<<"\n\n Candidate\t\tVotes Recived\t\t% of Total votes \n";
cout<<"\n------------------------------------------------------------------";
for (i=0;i<5; i++)
{
total =(c.set_voicesNO()/sum)*100;
cout<<"\n "<<c.set_name()<<"\t\t\t"<<c.set_voicesNO()<<"\t\t\t"<<total<<"\n";
}
//to stop the output screen
getch();
}النسبة المئوية تظهر صفر دائما ،، هل لاحدكم مدي يد العون لي
وكيف احسب الفائز ؟؟؟؟

