(Latest Revision: 03/25/2000)
03/25/2000 -- Added tip #4.

Tips on Writing the Tax Program



TIP #1
As indicated in the structure chart, it is a good design
decision to write three separate functions to compute the tax:
one function for each tax schedule.  It will work well to use a
a switch statment to determine which function is called to
compute the tax.

TIP #2
Code like this will get a "warning" from the compiler because a
real number is being assigned to an integer variable:  

int tax ;
if (txbleIncome > 34548) tax = 1521.08 +  0.093*(txbleIncome-34548) ;
		
Nevertheless the code above is OK.  It just computes the real
number corresponding to the expression, and then the decimal
part is "thrown away" when the value is assigned to the
variable.  The value that "tax" gets is incorrect by no more
than $0.99.

TIP #3

Code like this will do the job of computing the taxes:

if ( (txbleIncome >=  0) && (txbleIncome <=  5264) )
    tax =    0.00 + 0.01*(txbleIncome-0) ;
else if ( (txbleIncome >  5264) && (txbleIncome <=  12477) )
     tax =   52.64 + 0.02*(txbleIncome-5264) ;
else ... (... more of the same kind of code ...)

The kind of code above comes from direct copying of the table.
However code like the code below works from the bottom of a
table towards the top:

       if (txbleIncome > 34548) tax = 1521.08 + 0.093*(txbleIncome-34548) ;
  else if (txbleIncome > 27337) tax =  944.20 + 0.08*(txbleIncome-27337) ;
  else if (txbleIncome > 19692) tax =  485.50 + 0.06*(txbleIncome-19692) ;
  else ...  (... more of the same kind of code ...)

This kind of code works too, and it requires fewer terms.  You
can finish writing this code sooner and you are likely to make
fewer errors.

TIP #4

This example code shows how to treat the character input
of 'X', 'Y', or 'Z'

char  getStatus()
{ 
   char status ;

      // code here prints directions and prompt for the user.

   cin >> status ;

       // Note that you have to put char data in single quotes
       // so the compiler will not confuse char data with 
       // names for variables.

   if (status == 'X' || status == 'Y' || status == 'Z')
       return status ;   
   else 
   {
      cout << "BAD STATUS VALUE" << endl ;
      exit (-1) ;
   }
}

    // This function illustrates use of char data as the selector 
    // in a case statement.
int computeTax(char status, int txbleIncome)
{ 
  switch (status) 
  {
    case 'X': return (singleTax(txbleIncome)) ; break ;
    case 'Y': return (marriedTax(txbleIncome)) ; break ;
    case 'Z': return (headHouseTax(txbleIncome)) ; break ;
    default: cout << "BAD STATUS VALUE" << endl ;  return 0 ;
  }
}