/*
 * Solution to Problem 1 (C++)
 * 11th Annual CS Programming Contest
 * WCU Dept of Math and CS
 * Copyright 2000 , All Rights Reserved
 *
 * Problem Statement:
 * This program prompts the user for a series of purchases;
 * each is either taxable or nontaxable.  The user terminates
 * the input with a sentinel value, and the program totals the
 * purchases and applies the proper sales tax to form a grand total
 * which is shown to the user
 */

#include <iostream.h>

#define TAX_RATE 0.06

int main()
{
  double taxable = 0;
  double nontaxable = 0;
  double currentPurchase = 1; 
  char currentType;

  do
  {
    cout << "Enter a purchase followed by its type: " << endl;
    cin >> currentPurchase >> currentType;

	cout << currentPurchase << " " << currentType << endl;
 
    if ( currentType == 't' )
      taxable += currentPurchase;
    else if ( currentType == 'n')
      nontaxable += currentPurchase;
    else
      cout << "Bad type: try again.";


  } while ( currentPurchase != 0);

  double tax = taxable * TAX_RATE;

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


  cout << "Taxable total: $" << taxable << endl;
  cout << "Sales tax: $" << tax << endl;    
  cout << "Non-taxable total: $" << nontaxable << endl;  
  cout << "Grand Total: $" << taxable + tax + nontaxable << endl;
}

