SOURCE FILE: 020_taxProg2.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 maximum amount of braces to delimit sub-parts of
      statements.       
*/

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

#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.01 * income ;
     }
     else /* income is MORE than 40000, so ...  */
     {
        if (income <= 60000) 
        { 
           tax = 400 + 0.015 * (income - 40000) ; 
        }
        else  /* income is MORE than 60000, so ...  */
        {
           if (income <= 90000)
           {
              tax = 700 + 0.0225 * (income - 60000) ;
           }
           else  /* income is MORE than 90000, so ...  */
           {
              tax = 1375 + 0.03 * (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; 
}

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