Function is a block of codes that performs a specific task and only run when it is called.
void Greatest(string name1, string name2, int votes1, int votes2, int total_votes){
int v=(0.5*total_votes)+1;
if (votes1>=v){
cout<<"\nThe winner of the election is "<<name1;
}
else if(votes2>=v){
cout<<"\nThe winner of the election is "<<name2;
}
}
The function takes five argument. it then compares the votes of the two candidates with 50%+1 of the total valid votes. If the first candidate has at least 50%+1 of the total valid votes, the function prints the the first candidate as the winner of the election. Else it prints the name of the second candidate as the winner of the election.
Comments
Leave a comment