I tested it using the purchase price if 23.455, when doing it Iuse 0.005 to help with the rounding issue however it is not rounding right when I truncate it
For example
The Delmar store has a tax rate of 7.25% which should show a tax of 1.7004875. Rounding that it would be 1.70, even to account for the rounding in C with 0.005 it should still truncate to 1.70 however it is showing 1.71. What am I doing wrong?
Here is the program I have at the moment
Code:
#include <stdio.h>
#include <windows.h>
int main (void) //Main program function
{
char *stores[3] = {"Del Mar", "Encinitas", "La Jolla"};
float taxPercent[3]={7.25, 7.5, 7.75}; // Tax variable for all three stores
float price; //float variable for the price
do {
printf("\t\tKudler Fine Foods Tax Calculator\n\n"); // prints header
printf("Please enter the amount of your purchase: ");
scanf("%f", &price);
if (0.0 > price) {
printf("\n\nPurchase amount must be positive");
sleep(2000);
system("cls");
}
} while(price < 0.0);
float newPrice = price + 0.005;
float taxTotal[3] = {price * (taxPercent[0]/100), price * (taxPercent[1]/100), price * (taxPercent[2]/100)}; //calculates the total for each store
float totalPrice[3] = {price + taxTotal[0], price + taxTotal[1], price + taxTotal[2]};
printf("\n\n\t%s store\n", stores[0]); //prints tax information for Del Mar
printf("\n\tPurchase price: %.2f", newPrice);
printf("\n\tSales tax: %.2f", taxTotal[0] + 0.005);
printf("\n\tTotal Purchase Price: %.2f", totalPrice[0] + 0.005);
printf("\n\n\t%s store\n", stores[1]); //prints tax information for Del Mar
printf("\n\tPurchase price: %.2f", newPrice);
printf("\n\tSales tax: %.2f", taxTotal[1] + 0.005);
printf("\n\tTotal Price: %.2f", totalPrice[1] + 0.005);
printf("\n\n\t%s store\n", stores[2]); //prints tax information for Del Mar
printf("\n\tPurchase price: %.2f", newPrice);
printf("\n\tSales tax: %.2f", taxTotal[2] + 0.005);
printf("\n\tTotal Purchase Price: %.2f", totalPrice[2] + 0.005);
getch(); // waits for user to press a key
return 0; // return of int main()
} // end main