Answer to Question #255781 in C++ for mustapha shuraim

Question #255781

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 3 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-10-24T11:51:12-0400

a) Function is a block of code that performs a specific task to achieve a particular result.

b)void Greatest(string f, string s, int first, int second, int total){
	int first_candidate = first * 100 / total;
	int second_candidate =  second * 100 / total;
	
	if(second_candidate>50){
		cout<<"The winner is "<<s<<endl;
	}
	else if(first_candidate>50){
		cout<<"The winner is "<<s<<endl;
	}
	else{
		cout<<"No winner "<<endl;
	}
}

The logic behind the code is the use of decision statements to find the winner.

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