473,810 Members | 3,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tax calculation program in C

1 New Member
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\nLocati on? (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 = IndividualTaxes Owed (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 = IndividualTaxes Owed (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 = IndividualTaxes Owed (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\nInpu t 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\nHav e a nice day!");//end program

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

return 0;//normal end

}// end Main Program



// Individual TaxesOwed function definition - CR2

int IndividualTaxes Owed(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(fGrossReceip t<=0.0)(ClrScr( ), printf("\n\nInv alid Entry!! Program unstable restart program.\n"),
iError=1);//Entry validation, error checking - CR1,2

else

{printf ("\n\n\n\nYo u 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(fl oat 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(fGrossReceip t<=0.0)(iError= 1, printf("\n\nInv alid 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\tTota l Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTota l 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\tTota l Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTota l 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\tTota l Tax due is $%.2f.\n", fTotalTax);// display tax due on the gross amount

printf ("\t\t\tTota l 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
1 5206
Niheel
2,456 Recognized Expert Moderator Top Contributor
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

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

Similar topics

0
2488
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted to use a parent window that allows the user to launch the calculation in a seperate window, so that they could still click "stop" to write a value to a database or set a session level variable that the calculation would check to see if it should...
2
3916
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the calculated fields are not being populated. The database is a samll invoicing database on the form and report we have columns call Unit Cost. This is the actual cost of the part and is pulled from our parts master table and is displayed in a sub form...
4
3279
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the program is doing I show a window which contains a progress bar and a label. At some point during the execution the state of the calculation is changed, so I want to let the user know this. I have placed the creation of the form in a seperate thread...
4
2514
by: sara | last post by:
i am studying a computer engineering and i started taking programming using C++ since month i have question i think it`s easy for you all *prof.programmer* but it`s bit diffecult for me plzz i need your help. (: this is the question: ** A new telephone communication company needs a billing calculation program. The cost of a call is based on the following three inputs that should be entered by the user, and they are explained as follows.
6
2146
by: faizal87 | last post by:
i've some problems in creating a program using V.B since i'm new in learning this language. basically i learn V.B just by browsing the net by myself without any guide from other people. i need to work on my task (downloadable calculation) and i'd be glad if u help me sharing the code for calculation. thank you
5
6263
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a user modifies any of the x, y and z values.
3
3558
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really know nothing about advanced math, so I wrote a C program to help me: (BTW, I guess the result would be ln2.) #include <stdio.h>
6
4499
by: zandiago | last post by:
#include <cstring> #include <iostream> #include <iomanip> #include <cmath> #include <fstream> #include <string> #include <ctime> using namespace std;
1
2465
by: cnixuser | last post by:
I am posting this on behalf of a friend of mine who is trying to write a simple program that calcuates pi. He is trying to get as many decimal points as possible down in the calculation ;however, no matter what data type he seems to try, the greatest level of precision he can get is 6 decimal places. Below is a copy of his source code, can someone make a suggestion as to why float is only giving him 6 decimal places of precision? Any help would...
30
5716
by: Barry L. Bond | last post by:
Greetings! I just got a new Peet Brothers Ultimeter 2100 Weather Station. This new one has a way to display the heat index, if you press the "dew point" key twice. Being aware of all the controversy surrounding the exact calculation of the heat index, I would like my own software (which I programmed in the 1990's, when I got their Ultimeter 2000 weather station, but that one didn't show heat index) to display it. Living in Florida,...
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.