SOURCE FILE: 020_taxProg3.cpp



/* 
      This program calculates a progressive tax with the
      following characteristics:
     
      Tax the first 40000 at 1% rate. (tax on 40000 is 400)
      Tax the next 20000 at 1.5% rate (tax on 60000 is 700 = 400 + 300)
      Tax the next 30000 at 2.25% rate (tax on 90000 is 1375 = 700 + 675)
      Tax any income over 90000 at 3% rate.

      In figuring the tax, I used nested if-else statements 
      and a MINIMUM amount of braces to delimit sub-parts of
      statements.

      I also minimized the amount of some whitespace, so that I could
      put "if" keywords right after "else" keywords.

      Finally, I lined up certain things in columns to make parts of 
      the structure of the program easier to see.
      
      The compiler would see no significant difference between this 
      program (taxProg3.cpp) and this other program: taxProg2.cpp.
      The difference between them is basically only a difference in
      how they are formatted.
*/

/* ****************************** */

#include <iostream> 
using namespace std ; 

int main (void) 
{
  double income, tax ;

  cout << "\nPlease enter your taxable\n" ;
  cout << "income as a non-negative number: " ;
  cin >> income ;
  
  if (income < 0)
  { /* Error Message */

     cout << "\nYou entered a BAD VALUE for your income.\n" ;
     cout << "Please run the program again.\n\n" ;
  }
  else 
  { /* Figure and report the tax.  */
     
          if (income <= 40000)  tax =        0.0100 * income ;
     else if (income <= 60000)  tax =  400 + 0.0150 * (income - 40000) ; 
     else if (income <= 90000)  tax =  700 + 0.0225 * (income - 60000) ;
     else                       tax = 1375 + 0.0300 * (income - 90000) ;

     cout.setf (ios::fixed) ;
     cout.setf (ios::showpoint) ;
     cout.precision (2) ;

     cout << "\nYour taxable income is: " << income << endl ;
     cout << "For filing status Single your tax is: " << tax ;
     cout << endl << endl ;
  } 
 
  return 0; 
}

/* ****************************** */