Answer to Question #219151 in C++ for Onai Maxwell

Question #219151
The electoral petition of 2021 was aimed at determining the winner of the 2020 election. The
rule is that the winner of an election in Ghana must obtain at least 50% +1 of the valid votes
cast.

a. Explain the concept of function in C++

b. Declare a function called Greatest, your function should have five arguments
i. The two names of the presidential candidates with the most votes
ii. Total number of votes for each of them.
iii. Total valid votes cast.

c. Your function should declare that candidate that had at least 50%+1 of the valid votes
cast as winner.

d. Explain the logic behind the code
1
Expert's answer
2021-07-20T17:03:03-0400

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.





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS