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
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.
Comments
Leave a comment