Thread: Tax Calc program

  1. #1
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790

    Tax Calc program

    I just finished my little tax calc program, not the best, but I am trying to learn how to use structs, so just started with something basic. Heres the code:

    Code:
    #include <iostream.h>
    
    
    
    
    struct MONEY
    {
    	double hours, pay, total, gross, taxes;
    	
    };
    
    
    int main()
    {
    MONEY di;
    int input;
    bool end_prog = 0;
    	while (end_prog != 1)
    	{
    /* begining commentary*/
    		cout <<" this program outputs how much taxes you will pay a week,\n"
    			 << " month, or year, based upon your choice.\n"
    			 <<" the tax % is based upon income, the rates are :\n\n"
    			 << " 1. 5% if income <20,000\n"
    			 << " 2. 10% if 20000<income < 40000\n"
    			 << " 3. 15% if 40000< income < 60000\n\n";
    
    		cout <<" enter Hours worked:  ";
    		cin >> di.hours;
    		cout <<"\n\n";
    		cout << "enter pay per hour :   ";
    		cin >> di.pay;
    		cout <<"\n\n";
    
    		di.total = di.pay * di.hours;
    
    		di.gross =  di.total * 52;
    
    		/*calculation of taxes based on income*/
    		if (di.gross < 20000)
    		{
    			di.taxes = ((di.total/100 * 5)) ;
    		}
    		else if(20000 < di.gross < 40000)
    		{
    			di.taxes = ((di.total/100 * 10));
    		}
    		else if (40000 < di.gross < 60000)
    		{
    			di.taxes = ((di.total/100 * 15));
    		}
    
    		cout << "how long of a period do you want taxes calculated?\n\n"
    		     << " 1. a week\n"
    			 << " 2. a month\n"
    			 << " 3. a year\n";
    
    		cin >> input;
    
    		cout << "you make "<< di.total <<" dollars a week \n";
    		cout << (di.total * 4) <<"  dollars a month\n";
    		cout << " and" <<(di.total * 52)<<" dollars a year\n\n";
    
    		switch (input)
    		{
    		case 1:
    
    		cout <<"you pay $" << (di.taxes) <<" dollars in taxes a week\n\n\n";
    		break;
    
    		case 2:
    			cout <<"you pay $" << (di.taxes * 4) << "dollars in taxes a month\n\n\n";
    				break;
    		case 3:
    		cout <<"you pay $" << (di.taxes * 52) <<" dollars in taxes a  year\n\n\n";
    				break;
    		}
    
    
    		cout <<" do you want to quit?\n"
    			 << " Y or N:  ";
    		cin >> input;
    
    		if (input == 'Y' || 'y')
    		{
    			end_prog = 1;
    			cout <<endl;
    		}
    
    		else if ( input == 'N' || 'n')
    		{
    			end_prog = 0;
    			cout << "\n\n\n";
    		}
    
    
    	}
    
    
    	return 0;
    }
    and I am attaching the .cpp file for anyone who wants to use it.. Any suggestions? I am learning alot, having only really been with C++ for 2 weeks working straight
    Last edited by EvBladeRunnervE; 02-13-2003 at 03:06 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I recommend keeping it with cout throughout the whole program, since you used cout in the beginning of the program and printf towards the end. I also recommend that tax %s be constants, so that you only have to change them in one place. I didn't run the code, but it looks as if there is no way to get out of the for loop. you may want to add something that asks the user if they want to quit or keep going. i think a while loop would do best for that.

    also, you would want to start making your code more standard. iostream.h will give you backwards warnings on newer compilers, and i believe stdio.h and math.h would also (not sure about stdio and math).

    edit: you may want to work on your style as well.
    Last edited by alpha; 02-13-2003 at 02:53 PM.

  3. #3
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I changed all of the Printf's to cout's. what are the "newer" equivalents AKA standards to the include files I have?

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    you will also need to do one of the following:
    Code:
    using namespace std; //goes after includes, but before main
    //OR
    using std::cout;//goes after includes, but before main
    using std::endl;
    using std::cin;
    //OR
    std::cout << std::endl; //std:: in front of every cout, cerr, endl, cin, etc.
    also, i believe you won't need stdio anymore if everything is cout, and i believe you don't need math, so the only header really needed is iostream.
    Last edited by alpha; 02-13-2003 at 03:14 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. End Program
    By jhwebster1 in forum C Programming
    Replies: 7
    Last Post: 02-24-2006, 09:30 AM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Help with sample tax program
    By DaMonsta in forum C Programming
    Replies: 1
    Last Post: 05-15-2003, 03:45 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM