// This program repeatedly reads an income from // the file income.in until end-of-file. // Income under 6000 greenbacks is taxed at 30 // percent, and income greater than or equal to // 6000 greenbacks is taxed at 60 percent. // After reading each income, the program // outputs the income and tax to the file tax.out. #include #include #include using namespace std; const int cutoff = 6000; const float rate1 = 0.3; const float rate2 = 0.6; int main() { ifstream infile; ofstream outfile; infile.open( "income.in" ); outfile.open( "tax.out" ); if ( !infile ) { cout << "Unable to open income.in" << endl; exit( 0 ); } if ( !outfile ) { cout << "Unable to open tax.out" << endl; exit( 0 ); } int income, tax; while ( infile >> income ) { if ( income < cutoff ) tax = rate1 * income; else tax = rate2 * income; outfile << "Income = " << income << " greenbacks" << endl << "Tax = " << tax << " greenbacks" << endl; } infile.close(); outfile.close(); return 0; }