By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,601 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,601 IT Pros & Developers. It's quick & easy.

Tax calculation program in C

P: 1
I need to write a tax calculation program in C for a store chain. There 4 stores and 4 different tax rates .0700, .0725, .07500 and .0775
This is what i have so far...
any suggestions
#include <stdio.h>

int main ()

{

char (a StoreLocation=0)//Initialize variable for store
char b StoreLocation=1;
char c StoreLocation=2
char d StoreLocation=3

int iError = 0; // Error - improper entry indicator

int iRepeat; // function iteration control variable

char cContinue = 'y'; //Initialize variable continue program

float fTaxRateLH = .07750; // Tax Rate La Jolla

float fTaxRateEN = .07500; // Tax Rate Encinitas

float fTaxRateDM = .07250; // Tax Rate Del Mar

float fGrossReceipt=0.00;//Initialize Gross Receipts

float fTotalTax=0.00; //Initialize variable for total taxes



// start loop for program execution

{ClrScr();//Clear the screen

StoreLocation = '0';// Set location to zero

printf ("\n\nThis program computes sales tax on sales at one or all Kudler Foods locations.\n\n");//describe program

printf ("enter the number for the Kudler store location you need.\n\n"); // Display Ask for the store location - CR2

printf ("1 - DelMar\n");//selection 1 - CR2

printf ("2 - Encinitas\n");//selection 2 - CR2

printf ("3 - La Jolla\n");//selection 3 - CR2

printf ("4 - ALL\n");//selection 4 - CR2

printf ("\n\nLocation? (1,2,3,4) ");//prompt - CR2

cStoreLocation = getch();//get the store location and continue - CR2

ClrScr();//Clear the screen

switch (cStoreLocation)//run routine for any or all stores - CR2

{case 49://if the location is Del Mar - CR2

printf ("\n\nYou picked the DelMar Kudler location, where");// output location selection

(fTaxRate = fTaxRateDM);//assign tax rate for Del Mar

iError = IndividualTaxesOwed (fTaxRate, fGrossReceipt, fTotalTax, iError);/*function finds taxes owed for this location
and sets error condition if input error is detected - CR1,2*/

//end case

case 50://if the location is Encinitas - CR2

printf ("\n\n They picked the Encinitas Kudler location, where")// output location selection

(TaxRate = TaxRateEN);//assign tax rate for Encinitas

Error = IndividualTaxesOwed (fTaxRate, fGrossReceipt, fTotalTax, iError);/*function finds taxes owed for this location
and sets error condition if input error is detected - CR1,2*/

break;//end case

case 51://if the location is La Jolla - CR2

printf ("\n\nThey picked the La Jolla Kudler location, where");// output location selection

(fTaxRate = fTaxRateLH);//assign tax rate for La Jolla

iError = IndividualTaxesOwed (fTaxRate, fGrossReceipt, fTotalTax, iError);/*function finds taxes owed for this location
and sets error condition if input error is detected - CR1,2*/

break;//end case

case 52://if All Locations is selected - CR1

printf ("\n\nThey picked ALL Kudler locations.\n\n");// output location selection

Error = AllTaxesOwed (fTaxRate, fGrossReceipt, fTotalTax, fTaxRateLH, fTaxRateEN, fTaxRateDM, *function finds
taxes owed for all locations and sets error condition if input error is detected - CR1,2/

break;//end case

default: printf ("\n\n\nInput Error! When asked, please enter 1, 2, 3, or 4.\n\n");// error message for incorrect input - CR1,2

cStoreLocation = ("");// set location back to nothing

break;// End Default case

}//end switch

if (iError == 1)break; // Don't get another location if error is present

printf ("\nWould you like to try another Kudler location? Enter \"Y\" for yes ");//ask if the program is done

cContinue = getch();//get the answer



}//end do loop

while ( iError == 0 && (cContinue == 'y' || cContinue == 'Y'));//if no errors and continue program is (y)es, restart at selection



ClrScr();//Clear the screen

if(iError == 1)((printf("\n\n\n\n\n\nInput Error!! You entered a character, a zero amount, or a negative number.")),

(printf("\n\n\n\n\nThis program will now close. You must restart the program.")));// This is an output message for an abnormal program entry.

printf ("\n\n\n\n\nHave a nice day!");//end program

getch();//keep window open until <enter>

return 0;//normal end

}// end Main Program



// Individual TaxesOwed function definition - CR2

int IndividualTaxesOwed(float fTaxRate, float fGrossReceipt, float fTotalTax, int iError)// Function Title and variables passed

{

printf (" the tax rate is %.2f percent.\n\n\n", fTaxRate*100);//output tax rate

printf ("\nPlease enter the sale amount.\t$"); //get amount of gross sales

scanf ("%f", &fGrossReceipt);//accept gross sales amount - CR1

if(fGrossReceipt<=0.0)(ClrScr(), printf("\n\nInvalid Entry!! Program unstable restart program.\n"),
iError=1);//Entry validation, error checking - CR1,2

else

{printf ("\n\n\n\nYou entered a sales amount of $%.2f\n", fGrossReceipt);//repeat entered gross sales amount

fTotalTax = fGrossReceipt * fTaxRate;//calculate the taxes owed for that location by multiplying the gross amount by the tax rate

printf ("\nThe total tax due is $%.2f\n\n", fTotalTax);// display tax due on the gross amount

printf ("The total amount due is $%.2f\n\n", fTotalTax + fGrossReceipt);// display the total amount due - CR1

}

return (iError);//error status back to function call

}//end Individual Taxes owed function


// All Locations TaxesOwed function definition - CR1

int AllTaxesOwed(float fTaxRate, float fGrossReceipt, float fTotalTax, float fTaxRateLH, float fTaxRateEN, float fTaxRateDM, int iError)/* Function
Title and variables passed*/

{

int iRepeat;//declare variable for iteration count

printf ("\nPlease enter the sales amount.\t$"); //prompt for amount of gross sales

scanf ("%f", &fGrossReceipt);//get the gross sales amount CR1

ClrScr();//Clear the screen

if(fGrossReceipt<=0.0)(iError=1, printf("\n\nInvalid Entry!! Program unstable restart program.\n"));//Entry validation, error checking CR1,2

else

iRepeat = 1;//set iteration counter to 1 for first case

do {switch (iRepeat)//begin loop for number of stores

{case 1://Display data for the first location

printf ("\nYou entered a sales amount of $%.2f for each Kudler store.\\n", fGrossReceipt);// print gross sales amount

printf ("\nFor Kudler Del Mar: \t\tThe Tax rate is %.2f percent.\n", fTaxRateDM*100);//display tax rate for this store

fTotalTax = fGrossReceipt * fTaxRateDM;//calculate taxes owed for that location by multiplying the gross amount by the tax rate

printf ("\t\t\tTotal Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTotal Amount due is $%.2f.\n\n", fTotalTax + fGrossReceipt);// display the total amount due

iRepeat ++;//increment iRepeat

break;//end First location case



printf ("\nFor Kudler Encinitas: \t\tThe Tax rate is %.2f percent.\n", fTaxRateEN*100);//display tax rate for this store

fTotalTax = fGrossReceipt * fTaxRateEN;//calculate taxes owed for that location by multiplying the gross amount by the tax rate

printf ("\t\t\tTotal Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTotal Amount due is $%.2f.\n\n", fTotalTax + fGrossReceipt);// display the total amount due

iRepeat ++;//increment iRepeat

break;//end



printf ("\nFor Kudler La Jolla: \t\tThe Tax rate is %.2f percent.\n", fTaxRateLH*100);//display the tax rate for this store

fTotalTax = fGrossReceipt * fTaxRateLH;//calculate taxes owed for that location by multiplying the gross amount by tax rate

printf ("\t\t\tTotal Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTotal Amount due is $%.2f.\n\n", fTotalTax + fGrossReceipt);// display the total amount due

//increment iRepeat

break;//end case

default: break;// Error handler

} //end

}while ((iRepeat < 4)&& (iError == 0)); //end while after 3 iterations and there is no error.

return (iError);//error status back to function call

}//end All Taxes Owed function
Nov 13 '06 #1
Share this Question
Share on Google+
1 Reply


Expert Mod 100+
P: 2,328
Please post in the appropriate forum(moved from introductions to C/C++), and also be clear about what the problem with the code is.
Nov 13 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.