#include #include #include // for INT_MAX int main () { double earned_income; int age, dependents; for (;;) { cout << endl << "Please enter earned income, age, and dependents" << endl << "(all zeroes to stop): "; cin >> earned_income >> age >> dependents; if (cin.fail()) { // the input operation failed altogether (the user did not enter // a valid double value followed by two int values). // begin by outputting an error message. cout << "Garbage input ignored." << endl; // now reset cin and discard the balance of the current input line // (clear the deck so that we can try again). cin.clear (); cin.ignore (INT_MAX, '\n'); } else if ((earned_income == 0) && (age == 0) && (dependents == 0)) { return 0; // we're all done - go home } else if ((earned_income < 0) || (dependents < 0) || (age < 0)) { // the input values are unreasonable cout << "Unreasonable values ignored." << endl; } else { calculate_and_output_tax (earned_income, age, dependents); } } // end for (;;) } // end main