///////
//
// Student: Russell Lowke
//     T.F: Francis Crick
// Unit Three, Easy Supplementary - question 13 [worth 2pts],  7/7/2002
//
//  Requirement for membership in the Congress of the United States


#include <iostream>
#include <iomanip>

//
//  reads an integer from the keyboard,
//  uses error checking to ensure value is between minValue and maxValue
//
int getInt(char askStr[], int minValue, int maxValue)
{
	int mVar;
	bool inputOK = false;
	
	while (! inputOK) { 
	
		cout << askStr;						// ask query
		cin >> mVar;						// get input
		
		if ( mVar >= minValue && mVar <= maxValue )
			inputOK = true;					// input OK, exit loop
		else {
			cout << "Bad input: please enter a value between "
			     << minValue << " and " << maxValue << endl;
			cin.clear();					// clear error
			cin.ignore(80, '\n');			// empty buffer
		}
	}
	
	return mVar;
}


void main()
{
	int  age, lengthOfCitizenship;
	bool eligibleForHouse, eligibleForSenate;
	
	cout << endl << "CONGRESS ELIGIBILITY" << endl << endl;
	age                 = getInt("Enter age of candidate: ", 0, 120);
	lengthOfCitizenship = getInt("Enter years of U.S. citizenship: ", 0, 120);
	
	eligibleForHouse  = ( (age >= 25) && (lengthOfCitizenship >= 7) );
	eligibleForSenate = ( (age >= 30) && (lengthOfCitizenship >= 9) );
	
	cout << endl;
	
    if (! eligibleForHouse && ! eligibleForSenate)
    	cout << "The candidate is NOT eligible for election to either\n"
    		 << "the House of Representatives or the Senate.";
    else if ( eligibleForHouse && ! eligibleForSenate)
        cout << "The candidate is eligible for election to the House of\n"
    		 << "Representatives but is NOT eligible for election to\n"
    		 << "the Senate.";
    else if ( eligibleForHouse && eligibleForSenate)
    	cout << "The candidate is eligible for election to both the\n"
    		 << "House of Representatives and the Senate.";
    
    cout << endl;
}
