|
I'm in luck one of the students posted their response. I'll look through their code to see if it can help me create my own. Thx!
/*----------------------------------------------------------------------------- Program: Date: Author: Class: Requestor: Change: Change Request #1
Description: This C program will prompt the user to enter the purchase amount and will check the user's input for validity. The correct tax amount and total purchase amount will be calculated on the input value. The purchase amount, Tax amount, and Total Sale amount will be displayed for each store location at Kudler Fine Foods. Tax Rates: Del Mar (7.25%), Encinitas (7.5%), La Jolla (7.75%) -------------------------------------------------------------------------------*/ #include <stdio.h> // Include standard I/O libraries #include <stdlib.h> // Include standard libraries #include <math.h> // Include Math libraries
#define DMTaxRate 7.25 /* Set constant Tax Rate for Del Mar = 7.25% */ #define ENTaxRate 7.50 /* Set constant Tax Rate for Encinitas = 7.50% */ #define LJTaxRate 7.75 /* Set constant Tax Rate for La Jolla = 7.75% */
main() { char Purchase[32]; /* Declare program variables */ double Amount,DMTax,ENTax,LJTax; int i,NV=0;
/* Prompt user for Purchase Amount */ printf("\n\n\tKudler Fine Foods Tax Calculator\n\n"); printf("\n\n\tPlease Enter Amount of Purchase:"); printf("\n\n\t===> "); scanf("%s", Purchase);
/* Loop - Test each character in Input String (Purchase) */ 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 NV=1; /* Set Non-Numerical Value flag */ break; } } if (NV == 1) /* If Non-Numerical Value print Error Message */ { printf("\n\n\n\tError! Invalid Purchase Amount [ %s ]\n",Purchase); fflush(stdin); printf("\n\n\n\tPress any key to continue...\n\t"); getchar(); /* Pause to allow viewing of output on screen */ return 0; }
Amount=atof(Purchase); /* Convert Ascii character to Float */ DMTax=(Amount*DMTaxRate)/100; /* Calculate Tax Amount for Del Mar */ ENTax=(Amount*ENTaxRate)/100; /* Calculate Tax Amount for Encinitas */ LJTax=(Amount*LJTaxRate)/100; /* Calculate Tax Amount for La Jolla */
/* Display Tax Calculation output to the screen */ printf("\n\n\tKudler Fine Foods Tax Calculations by Store:\n\n"); printf("\n\tDel Mar Tax on $%.2f = $%4.2f Total = $%4.2f",Amount,DMTax,Amount+DMTax); printf("\n\tEncinitas Tax on $%.2f = $%4.2f Total = $%4.2f",Amount,ENTax,Amount+ENTax); printf("\n\tLa Jolla Tax on $%.2f = $%4.2f Total = $%4.2f",Amount,LJTax,Amount+LJTax);
fflush(stdin); printf("\n\n\n\tPress any key to continue...\n\t"); getchar(); /* Pause to allow viewing of output on screen */ return 0; }
|