Well it is allot of coding but I think I have done it. Tell me what you think
Code:
/********************************************************************
* Tax Calculator for CSS 561 *
* Author: Gregory Hegykozi *
* Due Date: February 7, 2010 *
* Facilitator: Michael Flanagan *
*********************************************************************
* Libraries Included *
* math.h *
* stdio.h *
* windows.h *
*********************************************************************
* Variables used *
*stores: an array storing the names of the stores *
*taxPercent: used as an array to store the tax price for each store *
*price: float variable for price *
*taxTotal: used as an array to calculate tax totals *
*totalPrice: float variable to determine total purchase *
*********************************************************************
* Company *
* Kudler Fine Foods *
*********************************************************************
* Stores Included *
* Delmar *
* Encinitas *
* La Jolla *
*********************************************************************
* Main Version *
* Version: Create a tax calcutator that gives prices for *
* the 3 Kudler Fine Foods Store showing the tax for 125.00 dollars *
*********************************************************************
* Additions *
* First Addition: Add in the ability for the user to choose their *
* own purchase price while checking that the user does not put *
* in a negative number while showing
********************************************************************/
#include <math.h>
#include <stdio.h>
#include <windows.h>
int main (void) //Main program function
{
char *stores[3] = {"Del Mar", "Encinitas", "La Jolla"}; //store variables
float taxPercent[3]={7.25, 7.5, 7.75}; // Tax variable for all three stores
float price; //float variable for the price
do { // starts a do while loop
printf("\t\tKudler Fine Foods Tax Calculator\n\n"); // prints header
printf("Please enter the amount of your purchase: "); //asks for purchase amount
scanf("%f", &price); // scans user input
// verifies user input was positive
if (0.0 > price) {
printf("\n\nPurchase amount must be positive");
sleep(2000);
system("cls");
}
} while(price < 0.0);
// creates usable variables for price, tax, and total purchase
short saleTax[3] = {(((taxPercent[0]/100) * price) + 0.005) * 100, (((taxPercent[1]/100) * price) + 0.005) * 100, (((taxPercent[2]/100) * price) + 0.005) * 100};
short decimal[3] = {saleTax[0] % 100, saleTax[1] % 100, saleTax[2] % 100};
short wholeTax[3] = {saleTax[0]/100, saleTax[1]/100, saleTax[2]/100};
float roundPrice = {price + 0.005};
float taxTotal[3] = {floor((price*(taxPercent[0]/100))*1000)/1000, floor((price*(taxPercent[1]/100))*1000)/1000, floor((price*(taxPercent[2]/100))*1000)/1000};
float totalPrice[3] = {roundPrice + taxTotal[0],roundPrice + taxTotal[1],roundPrice + taxTotal[2]};
//prints purchase information for Del Mar
printf("\n\n\t%s store\n", stores[0]);
printf("\n\tPurchase price: %.2f", roundPrice);
printf("\n\tSales tax: %d.%d", wholeTax[0], decimal[0]);
printf("\n\tTotal Purchase Price: %.2f", totalPrice[0]);
//end purchase information for Del Mar
//prints purchase information for Encinitas
printf("\n\n\t%s store\n", stores[1]);
printf("\n\tPurchase price: %.2f", roundPrice);
printf("\n\tSales tax: %d.%d", wholeTax[1], decimal[1]);
printf("\n\tTotal Price: %.2f", totalPrice[1]);
//end purchase information for Encinitas
//prints purchase information for La Jolla
printf("\n\n\t%s store\n", stores[2]);
printf("\n\tPurchase price: %.2f", roundPrice);
printf("\n\tSales tax: %d.%d", wholeTax[2], decimal[2]);
printf("\n\tTotal Purchase Price: %.2f", totalPrice[2]);
//end purchase information for La Jolla
getch(); // waits for user to press a key
return 0; // return of int main()
} // end main