A person is eligible to be a US senator if they are at least

A person is eligible to be a US senator if they are at least 30 years old and have been a US citizen for at least 9 years. To be a US representative these numbers are 25 and 7, respectively. Write a function, called congress0, that takes two formal parameters: a person\'s age (int) and years of citizenship (int) as input and returns their eligibility for the Senate and House. The return value of the function is one of the following three (1) * \'Eligible for the Senate and the House, * (2) * \'Eligible only for the House, * or (3) * \'Not eligible for Congress.* The caller of the function congress0 in the test0 function then prints a message using the format shown in the next problem. You must use If-elif-else statements In your solution. Your congress0 function must not print anything. Do not Import external module In your solution.

Solution

I am assuming, required programming language is C++

#include <iostream>
using namespace std;

string congress( int age_of_person, int years_of_citizenship ){
   bool eligible_for_us_senator = false;
   bool eligible_for_us_representative = false;
  
   if( age_of_person >= 25 && years_of_citizenship >= 7){
       eligible_for_us_representative = true;
   }
   if( age_of_person >= 30 && years_of_citizenship >= 9){
       eligible_for_us_senator = true;
   }

   if( eligible_for_us_senator && eligible_for_us_representative ){
       return \"Eligible for the Senate and the House\";
   }
   else if( eligible_for_us_representative ){
       return \"Eligible only for the House\";
   }
   else{
       //if not eligible_for_us_representative, then also not eligible_for_us_senator
       return \"Not eligible for Congress\";
   }
}

void test(){
   string a = congress( 26, 8 );
   cout << a << endl;
}

int main(){
   test();
}

 A person is eligible to be a US senator if they are at least 30 years old and have been a US citizen for at least 9 years. To be a US representative these numb

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site