( Latest Revision: Wed Oct 6 09:41:30 PDT 2004 )

Tips on Writing the Tax Program



TIP #1 

As indicated in the structure chart, it is a good design decision to
write four separate functions to compute the tax:  one function for
each tax schedule.  It will work well to use a a switch statement to
determine which function is called to compute the tax.  (See TIP #3
for example code for the switch statement.)

TIP #2

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

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

This example code shows how to treat the character
input of 'S', 'H', 'J', or 'M'

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 == 'S' || status == 'H' 
            || status == 'J' || status == 'M')
         return status ;   
   else 
   {
      cout << "BAD STATUS VALUE" << endl ;
      exit (-1) ;
   }
}

    // This function illustrates use of char data as the
    selector // in a case statement.

/* Figure the tax on txbleIncome, using the table for filing
   status "status" */

int computeTax(char status, int txbleIncome)
{ 
  int tax ;
  switch (status) 
  {
    case 'S': tax = singleTax(txbleIncome)     ; break ;
    case 'H': tax = headHouseTax(txbleIncome)  ; break ;
    case 'J': tax = marriedJQWTax(txbleIncome) ; break ;
    case 'M': tax = marriedFSTax(txbleIncome)  ; break ;
    default: cout << "BAD STATUS VALUE" << endl ; tax = 0 ;
  }
  return tax ;
}