In: Computer Science
In congress, members typically vote electronically. A
bill requires a simple majority of
“Yea” votes (more than 50%) to pass. There are 435 members in the
House of Represen-
tatives and 100 in the Senate. Write a function that declares two
parameters: the number
of “Yea” votes, and which house is voting (the House of
Representatives or the Senate)
and returns the value True if the bill received enough votes to
pass, and False if it did not.
// C++ Code:-
#include<iostream>
using namespace std;
// function that declares two parameters: the
number
// of “Yea” votes, and which house is voting (the House of
Representatives or
// the Senate) and returns the value True if the bill received
enough votes to
// pass, and False if it did not.
bool check_bill_majority(int vote,int house)
{
// 1 means house of representative and 50% of 435 = 217.5 .
Here we consider
// 218 .
if(house==1)
{
if(vote>=218)
return true;
else
return false;
}
// 2 means house of Senate and 50% of 100 is 50 and votes
must be more than 50.
else if(house == 2)
{
if(vote>50)
return true;
else
return false;
}
}
int main()
{
// In this program we input from user the house selection
and number of vote.
// user input 1 for house of representative or 2 for
Senate.
int house,vote;
cout<<"Enter House : ";
cin>>house;
// User input the number of 'Yea' vote.
cout<<"Enter Total number of votes : ";
cin>>vote;
// Calling function to check whether the bill is pass or
not.
bool flag = check_bill_majority(vote,house);
// If flag is true means bill is pass.
if(flag)
cout<<"Bill is Successfully passed."<<endl;
else
cout<<"Bill is not passed"<<endl;
return 0;
}