Help with Tax calculator program

This is a discussion on Help with Tax calculator program within the C++ Programming forums, part of the General Programming Boards category; How do i change this to input files or a struct to enter a series of data to the program. ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    51

    Help with Tax calculator program

    How do i change this to input files or a struct to enter a series of data to the program. I am fine with doing programs asking for input. I get confused on the struct parts. Please help me thru this. It is driving me nuts.

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    struct Employee
    {
    	int employeeID, numDependent;
    	double grossPay, netPay,
    		   cityTax, fedTax, 
    		   cityTaxToDate, fedTaxToDate,
    		   grossPayToDate,
    		   payRate, hourWorked;
    };
    
    struct Tax
    {
    	double city;
    	double fed;
    };
    
    
    void calculateTaxes(Tax &, Employee *, int const);
    
    void main()
    {
    	int const numEmployee = 3;
    
    	Tax rate;
    	rate.city = 1.15;
    	rate.fed = 20;
    	
    	Employee test[numEmployee];
    
    	for(int i=0; i < numEmployee; i++)
    	{
    		cout<<"\nEnter employee ID: ";
    		cin>>test[i].employeeID;
    		cout<<"Enter the number of dependents: ";
    		cin>>test[i].numDependent;
    		cout<<"Enter pay rate: ";
    		cin>>test[i].payRate;
    		cout<<"Enter the hours worked: ";
    		cin>>test[i].hourWorked;
    		cout<<"Enter city tax withheld to date: ";
    		cin>>test[i].cityTaxToDate;
    		cout<<"Enter federal tax withheld to date: ";
    		cin>>test[i].fedTaxToDate;
    		cout<<"Enter gross pay to date: ";
    		cin>>test[i].grossPayToDate;
    	}
    	calculateTaxes(rate, test, numEmployee);
    
    	cout<<setw(10)<<"\nemployee ID"<<setw(10)<<"gross pay"
    		<<setw(10)<<"net pay"<<setw(10)<<"city tax"
    		<<setw(13)<<"federal tax"<<setw(15)<<"total withheld"<<endl;
    
    	for(int j=0; j < numEmployee; j++)
    	{
    		cout <<setiosflags(ios::fixed | ios::showpoint)<<setprecision(2)
    			<<setw(10)<<test[j].employeeID<<setw(10)<<test[j].grossPay
    			<<setw(10)<<test[j].netPay<<setw(10)<<test[j].cityTax
    			<<setw(13)<<test[j].fedTax
    			<<setw(15)<<(test[j].cityTaxToDate + test[j].fedTaxToDate)<<endl;
    	}
    
    }
    
    void calculateTaxes(Tax &t, Employee *e, int const numE)
    {
    	for(int i=0; i < numE; i++)
    	{
    		e[i].grossPay = (e[i].payRate)*(e[i].hourWorked);
    		if(e[i].grossPayToDate < 40000)
    			e[i].cityTax = (e[i].grossPay)*(t.city/100);
    		else
    			e[i].cityTax = 0;
    		e[i].fedTax = (e[i].grossPay - 50*e[i].numDependent)*(t.fed/100);
    		e[i].netPay = e[i].grossPay - e[i].cityTax - e[i].fedTax;
    		e[i].cityTaxToDate = e[i].cityTaxToDate + e[i].cityTax;
    		e[i].fedTaxToDate = e[i].fedTaxToDate + e[i].fedTax;
    		e[i].grossPayToDate = e[i].grossPayToDate + e[i].grossPay;
    	}
    }

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    ok exactly what is causing you trouble?

    and please delete your other post.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sales tax
    By Mark_Guy in forum C Programming
    Replies: 0
    Last Post: 10-22-2008, 09:47 AM
  2. Big help for big program
    By Mahesh in forum C Programming
    Replies: 1
    Last Post: 05-04-2005, 11:02 AM
  3. multi file project error
    By dantestwin in forum C++ Programming
    Replies: 14
    Last Post: 07-22-2004, 01:10 AM
  4. Replies: 3
    Last Post: 11-03-2003, 08:55 PM
  5. Help with sample tax program
    By DaMonsta in forum C Programming
    Replies: 1
    Last Post: 05-15-2003, 04:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21