The code is below:
#include <stdio.h>
#include <system.h>
#include <ctype.h>
#include <stdlib.h>
/*The main function*/
void main()
{
char Purchase[32]; /* Declare variables */
int i,Return=0;
/*Variables for tax calculator*/
int iResponse;
#define DelMarRate 7.25
#define EncinitasRate 7.5
#define LaJollaRate 7.75
float DelMarTax = 0.0;
float EncinitasTax = 0.0;
float LaJollaTax = 0.0;
float Amount = 0.0;
/*Sales tax calculations for each of Kudler's locations*/
DelMarTax = Amount * DelMarRate / 100;
EncinitasTax = Amount * EncinitasRate / 100;
LaJollaTax = Amount * LaJollaRate / 100;
/*Menu to chose location*/
printf("\n*********************************");
printf("\n* Welcome to Kudler Fine foods! *");
printf("\n*********************************");
printf("\n\n");
printf("\n1. Del Mar\n");
printf("\n2. Encinitas\n");
printf("\n3. La Jolla\n");
printf("\n4. End Program\n");
printf("\nPlease Choose Kudler Location or 4 to exit: ");//Lets user know what tp input
do { /*Start loop*/
scanf("%d", &iResponse);
if (iResponse == 1 || iResponse <= 3) //Validates user input
{
printf("\n\nPlease Enter the customer's purchase amount:$"); //display for user and prompt for input
}
else
{
printf("\nInvalid entry. Please select another option!\n");//Shows error and prompts user for a correct entry
}
scanf("%f", &Amount);
switch (iResponse){ /*Switch for case selection*/
/*Displays cases for tax calculation output*/
case 1: /*Tax Calculation output for Del Mar*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message and allow user to re-enter purchase price */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Re-enter Purchase Amount:$");
scanf("%s", Purchase);
}
DelMarTax = Amount * DelMarRate / 100;
printf("\nDel Mar Tax on $%.2f = $%4.2f; Total = $%4.2f",Amount,DelMarTax,Amount+DelMarTax);
printf("\n\n\n");
printf("\nChoose another city or 4 to exit program: ");/*prompt user for input*/
break;
case 2: /*Tax Calculation output for Encinitis*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message and allow user to re-enter purchase price */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Re-enter Purchase Amount:$");
scanf("%s", Purchase);
}
EncinitasTax = Amount * EncinitasRate / 100;
printf("\nEncinitas Tax on $%.2f = $%4.2f; Total = $%4.2f",Amount,EncinitasTax,Amount+EncinitasTax);
printf("\n\n\n");
printf("\nChoose another city or 4 to exit program: ");/*prompt user for input*/
break;
case 3: /*Tax Calculation output for LaJolla*/
for(i=0; Purchase[i]; i++)
{
if(Purchase[i] < '0' || Purchase[i] > '9') /* Test for a numeric value (0-9) */
{
if (Purchase[i] == '.') /* If character is a decimal continue */
continue;
else
Return=1; /* Set Non-Numerical Value flag */
break;
}
}
if (Return == 1) /* If Non-Numerical Value print Error Message and allow user to re-enter purchase price */
{
printf("\n\nError! Invalid Purchase Amount [ %s ]\n",Purchase);
fflush(stdin);
printf("\n\nPlease Re-enter Purchase Amount:$");
scanf("%s", Purchase);
}
LaJollaTax = Amount * LaJollaRate / 100;
printf("\nLa Jolla Tax on $%.2f = $%4.2f; Total = $%4.2f",Amount,LaJollaTax,Amount+LaJollaTax);
printf("\n\n\n");
printf("\nChoose another city or 4 to exit program: ");/*prompt user for input*/
break;
case 4:
printf("\nThank You for using the Kudler Fine Foods Tax Calculator\n"); //ends program
printf("\n\nPlease Press The Enter Key To Exit Program!\n\n");
} /*End Switch*/
} while (iResponse!=4); /*End while loop*/
scanf("%c\n");
}/*end main*/
Edited by WingedPanther, 08 November 2009 - 10:54 AM.
fix code tags


Sign In
Create Account

Back to top









