Salary Program help

This is a discussion on Salary Program help within the C++ Programming forums, part of the General Programming Boards category; Hello fellow programmers I was recently trying to make a salary program for work... the employee is paid $16.78/hour. and ...

  1. #1
    new to c++
    Join Date
    Feb 2009
    Posts
    53

    Salary Program help

    Hello fellow programmers
    I was recently trying to make a salary program for work...
    the employee is paid $16.78/hour. and overtime after40hrs of $16.78/2 per hour after that.. there is 6% ssecurity tax, 14% for federal income tax, 5% for state income tax, and $10 per week for union dues. also if there are more than 3 dependents: additional $35 for health insurance. need to output gross pay, each withholding amount, and net pay for the week.
    I think its right, but when i debug it, it says that "Run-Time Check Failure #3 - The variable 'hours' is being used without being initialized." and also Run-Time Check Failure #3 - The variable 'dependents' is being used without being initialized." window pops up. I thought that I did initialize it, but apparently not. im using VS 2008. also any pointers on how to make program better.

    Thank you

    my code:
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main(){
    
    
    int rate,hours,overtime,overtimerate,undues,overtimehours;
    int dependents,dependnum,netpay,grosspay,sstaxt,fitaxt,sitaxt;		//initializes all the variables
    string dependanswer;
    
    overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    
    
    cout<<"How many hours were worked? \n";		//asks how many hours worked
    cin>>hours;
    
    cout<<"Do you have any dependents? <Y or N>? \n"; //do yo have dependents
    cin>>dependanswer;	
    
    if(hours>=41 && dependanswer=="y" || dependanswer=="Y" ){		//if you worked overtime and have dependents
    	
    	cout<<"How many dependents do you have? \n";
    	cin>>dependnum;
    
    if(dependnum>=3){		//if you have 3 or more dependents
    		
    		overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    		grosspay=hours*rate+overtime;
    		netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
    		cout<<"Gross Pay: $"<<grosspay<<" \n";
    		cout<<"Overtime hours: "<<overtimehours<<" \n";
    		cout<<"Social Security: $"<<sstaxt<<" \n";
    		cout<<"Federal Income: $"<<fitaxt<<" \n";
    		cout<<"State Income: $"<<sstaxt<<" \n";
    		cout<<"Union Dues: $10 \n";
    		cout<<"Health Insurance: $"<<dependents<<" \n";
    		cout<<"Net Pay: $"<<netpay<<" \n";
    }
    
    if(dependnum<=2){		//if you have less than 3 dependents
    
    	overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    		grosspay=hours*rate+overtime;
    		netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    	cout<<"Gross Pay: $"<<grosspay<<" \n";
    	cout<<"Overtime hours: "<<overtimehours<<" \n";
    	cout<<"Social Security: $"<<sstaxt<<" \n";
    	cout<<"Federal Income: $"<<fitaxt<<" \n";
    	cout<<"State Income: $"<<sstaxt<<" \n";
    	cout<<"Union Dues: $10 \n";
    	cout<<"Health Insurance: $0 \n";
    	cout<<"Net Pay: $"<<netpay<<" \n";
    }
    	
    }
    	
    	
    if(hours>=41 && dependanswer=="n" ||dependanswer=="N"){		//if overtime & you dont have dependents
    
    	overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    grosspay=hours*rate+overtime;
    netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    cout<<"Gross Pay: $"<<grosspay<<" \n";
    cout<<"Overtime hours: "<<overtimehours<<" \n";
    cout<<"Social Security: $"<<sstaxt<<" \n";
    cout<<"Federal Income: $"<<fitaxt<<" \n";
    cout<<"State Income: $"<<sstaxt<<" \n";
    cout<<"Union Dues: $10 \n";
    cout<<"Health Insurance: $"<<dependents<<" \n";
    cout<<"Net Pay: $"<<netpay<<" \n";
    
    	}
    
    if(hours<=40 && dependanswer=="y" || dependanswer=="Y"){		//if no overtime and dependents
    
    	cout<<"How many dependents do you have? \n";
    	cin>>dependnum;
    
    if(dependnum>=3){		//if you have 3 or more dependents
    
    	overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    		netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
    		cout<<"Gross Pay: $"<<grosspay<<" \n";
    		cout<<"Overtime hours: 0 \n";
    		cout<<"Social Security: $"<<sstaxt<<" \n";
    		cout<<"Federal Income: $"<<fitaxt<<" \n";
    		cout<<"State Income: $"<<sstaxt<<" \n";
    		cout<<"Union Dues: $10 \n";
    		cout<<"Health Insurance: $"<<dependents<<" \n";
    		cout<<"Net Pay: $"<<netpay<<" \n";
    }
    
    if(dependnum<=2){		//if you have less than 3 dependents
    
    	overtimehours=hours-40;
    overtimerate=16.78/2;
    rate=16.78;
    grosspay=rate*hours;
    overtime=overtimehours*overtimerate;
    sstaxt=grosspay*.06;
    fitaxt=grosspay*.14;
    sitaxt=grosspay*.05;
    undues=10;
    		netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    	cout<<"Gross Pay: $"<<grosspay<<" \n";
    	cout<<"Overtime hours: 0 \n";
    	cout<<"Social Security: $"<<sstaxt<<" \n";
    	cout<<"Federal Income: $"<<fitaxt<<" \n";
    	cout<<"State Income: $"<<sstaxt<<" \n";
    	cout<<"Union Dues: $10 \n";
    	cout<<"Health Insurance: $"<<dependents<<" \n";
    	cout<<"Net Pay: $"<<netpay<<" \n";
    }
    	
    }
    
    
    
    
    	system("pause");
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    Code:
    int dependents,dependnum,netpay,grosspay,sstaxt,fitaxt,sitaxt;		//initializes all the variables
    Is defining the variables. BUT it is NOT initializing any of these variables.

    You never assign a value to dependents before you use it.

    Also it would help to indent your program properly.


    Jim
    Last edited by jimblumberg; 09-26-2010 at 01:54 PM.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Quote Originally Posted by jimblumberg View Post
    Also it would help to indent your program properly.
    Let me correct that for you:
    The current indentation unacceptable.
    You MUST indent properly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    arent I initializing the variables each time in the if statements?...I need those variables in order to get gross pay,netpay, overtime, and other variables. Im kind of new to c++, I was wondering if i need to initialize each time in the if statements. also i know that i need to indent better, i had it running about the same(with errors) so i just copy and pasted the code where i wanted it.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    We cannot read your code. Thus, you need to indent it.
    If you don't do that, then few are going to bother looking at the code. I know I certainly will not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    You should always initialize variables when you define them. If you do a search of your code for "dependents" you will see that you never assign a value to it.


    Jim

  7. #7
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    ok, it is still showing up with the "hours" window. i updated my code. I can now understand it better. i also added an if no overtime and no dependents statement. it will still run, but calculates my grosspay wrong.

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main(){
    
    
    float rate,hours,overtime,overtimerate,undues,overtimehours;
    float dependents,dependnum,netpay,grosspay,sstaxt,fitaxt,sitaxt;		//declares variables
    string dependanswer;
    
    
    				overtimehours=hours-40;
    				overtimerate=16.78/2;
    				rate=16.78;
    				grosspay=rate*hours;
    				overtime=overtimehours*overtimerate;
    				sstaxt=grosspay*.06;
    				fitaxt=grosspay*.14;
    				sitaxt=grosspay*.05;
    				undues=10;
    				dependents=35;
    
    
    cout<<"How many hours were worked? \n";		//asks how many hours worked
    	cin>>hours;
    
    cout<<"Do you have any dependents? <Y or N>? \n"; //do yo have dependents
    	cin>>dependanswer;	
    
    if(hours>=41 && dependanswer=="y" || dependanswer=="Y" ){		//if you worked overtime and have dependents
    	
    	cout<<"How many dependents do you have? \n";
    		cin>>dependnum;
    
    					if(dependnum>=3){				//if you have 3 or more dependents		
    							
    					overtimehours=hours-40;
    					overtimerate=16.78/2;
    					rate=16.78;
    					overtime=overtimehours*overtimerate;
    					sstaxt=grosspay*.06;
    					fitaxt=grosspay*.14;
    					sitaxt=grosspay*.05;
    					undues=10;
    					dependents=35;
    					grosspay=hours*rate+overtime;
    					netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
    							cout<<"Gross Pay: $"<<grosspay<<" \n";					//outputs what i want
    							cout<<"Overtime hours: "<<overtimehours<<" \n";
    							cout<<"Social Security: $"<<sstaxt<<" \n";
    							cout<<"Federal Income: $"<<fitaxt<<" \n";
    							cout<<"State Income: $"<<sstaxt<<" \n";
    							cout<<"Union Dues: $10 \n";
    							cout<<"Health Insurance: $"<<dependents<<" \n";
    							cout<<"Net Pay: $"<<netpay<<" \n";
    							}
    
    									if(dependnum<=2){		//if you have less than 3 dependents
    
    									overtimehours=hours-40;
    									overtimerate=16.78/2;
    									rate=16.78;
    									overtime=overtimehours*overtimerate;
    									sstaxt=grosspay*.06;
    									fitaxt=grosspay*.14;
    									sitaxt=grosspay*.05;
    									undues=10;
    									grosspay=hours*rate+overtime;
    									netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    
    										cout<<"Gross Pay: $"<<grosspay<<" \n";
    										cout<<"Overtime hours: "<<overtimehours<<" \n";
    										cout<<"Social Security: $"<<sstaxt<<" \n";
    										cout<<"Federal Income: $"<<fitaxt<<" \n";
    										cout<<"State Income: $"<<sstaxt<<" \n";
    										cout<<"Union Dues: $10 \n";
    										cout<<"Health Insurance: $0 \n";
    										cout<<"Net Pay: $"<<netpay<<" \n";
    										}
    	
    }
    	
    	
    if(hours>=41 && dependanswer=="n" ||dependanswer=="N"){		//if overtime & you dont have dependents
    
    			overtimehours=hours-40;
    			overtimerate=16.78/2;
    			rate=16.78;
    			overtime=overtimehours*overtimerate;
    			sstaxt=grosspay*.06;
    			fitaxt=grosspay*.14;
    			sitaxt=grosspay*.05;
    			undues=10;
    			grosspay=hours*rate+overtime;
    			netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    					cout<<"Gross Pay: $"<<grosspay<<" \n";
    					cout<<"Overtime hours: "<<overtimehours<<" \n";
    					cout<<"Social Security: $"<<sstaxt<<" \n";
    					cout<<"Federal Income: $"<<fitaxt<<" \n";
    					cout<<"State Income: $"<<sstaxt<<" \n";
    					cout<<"Union Dues: $10 \n";
    					cout<<"Health Insurance: $0 \n";
    					cout<<"Net Pay: $"<<netpay<<" \n";
    
    }
    
    if(hours<=40 && dependanswer=="y" || dependanswer=="Y"){		//if no overtime and dependents
    
    	cout<<"How many dependents do you have? \n";
    	cin>>dependnum;
    
    				if(dependnum>=3){		//if you have 3 or more dependents
    
    				rate=16.78;
    				grosspay=rate*hours;
    				sstaxt=grosspay*.06;
    				fitaxt=grosspay*.14;
    				sitaxt=grosspay*.05;
    				undues=10;
    				dependents=35;
    				netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
    						cout<<"Gross Pay: $"<<grosspay<<" \n";
    						cout<<"Overtime hours: 0 \n";
    						cout<<"Social Security: $"<<sstaxt<<" \n";
    						cout<<"Federal Income: $"<<fitaxt<<" \n";
    						cout<<"State Income: $"<<sstaxt<<" \n";
    						cout<<"Union Dues: $10 \n";
    						cout<<"Health Insurance: $"<<dependents<<" \n";
    						cout<<"Net Pay: $"<<netpay<<" \n";
    						}
    
    												if(dependnum<=2){		//if you have less than 3 dependents
    
    													
    													rate=16.78;
    													grosspay=rate*hours;
    													sstaxt=grosspay*.06;
    													fitaxt=grosspay*.14;
    													sitaxt=grosspay*.05;
    													undues=10;
    													netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    														cout<<"Gross Pay: $"<<grosspay<<" \n";
    														cout<<"Overtime hours: 0 \n";
    														cout<<"Social Security: $"<<sstaxt<<" \n";
    														cout<<"Federal Income: $"<<fitaxt<<" \n";
    														cout<<"State Income: $"<<sstaxt<<" \n";
    														cout<<"Union Dues: $10 \n";
    														cout<<"Health Insurance: $0 \n";
    														cout<<"Net Pay: $"<<netpay<<" \n";
    														}
    }
    
    if(hours<=40 &&dependanswer=="n"||dependanswer=="N"){		//if no overtime and no dependents
    
    			rate=16.78;
    			grosspay=rate*hours;
    			sstaxt=grosspay*.06;
    			fitaxt=grosspay*.14;
    			sitaxt=grosspay*.05;
    			undues=10;
    			netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    					cout<<"Gross Pay: $"<<grosspay<<" \n";
    					cout<<"Overtime hours: 0 \n";
    					cout<<"Social Security: $"<<sstaxt<<" \n";
    					cout<<"Federal Income: $"<<fitaxt<<" \n";
    					cout<<"State Income: $"<<sstaxt<<" \n";
    					cout<<"Union Dues: $10 \n";
    					cout<<"Health Insurance: $0 \n";
    					cout<<"Net Pay: $"<<netpay<<" \n";
    
    }
    
    
    
    	system("pause");
    	return 0;
    }
    Last edited by rfoor; 09-26-2010 at 03:36 PM.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Code is still improperly and excessively indented.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    2,698
    INDENTATION

    What is it doing wrong? What is it producing for your answer and what do you think the answer should be?

    Also you should up the error message level to the highest setting.

    You have some "if" statements that should have parentheses
    "warning: suggest parentheses around ‘&&’ within ‘||’ " (line 31).

    Jim

  10. #10
    new to c++
    Join Date
    Feb 2009
    Posts
    53
    I guess that i need an indentation lesson. But it runs good now. I have tested it. the only thing that i dont like about it is that it gives more decimal places than i want. I think its like setprecision or something like that. do i have to do that setprecision code for every time i output what i want, or can i just make like a 'master' setprecision code for everything. and how?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Here is how to indent:
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main(){
    
    
        float rate,hours,overtime,overtimerate,undues,overtimehours;
        float dependents,dependnum,netpay,grosspay,sstaxt,fitaxt,sitaxt;        //declares variables
        string dependanswer;
    
    
        overtimehours=hours-40;
        overtimerate=16.78/2;
        rate=16.78;
        grosspay=rate*hours;
        overtime=overtimehours*overtimerate;
        sstaxt=grosspay*.06;
        fitaxt=grosspay*.14;
        sitaxt=grosspay*.05;
        undues=10;
        dependents=35;
    
    
        cout<<"How many hours were worked? \n";        //asks how many hours worked
        cin>>hours;
    
        cout<<"Do you have any dependents? <Y or N>? \n"; //do yo have dependents
        cin>>dependanswer;    
    
        if(hours>=41 && dependanswer=="y" || dependanswer=="Y" ){        //if you worked overtime and have dependents
    
            cout<<"How many dependents do you have? \n";
            cin>>dependnum;
    
            if(dependnum>=3){                //if you have 3 or more dependents        
    
                overtimehours=hours-40;
                overtimerate=16.78/2;
                rate=16.78;
                overtime=overtimehours*overtimerate;
                sstaxt=grosspay*.06;
                fitaxt=grosspay*.14;
                sitaxt=grosspay*.05;
                undues=10;
                dependents=35;
                grosspay=hours*rate+overtime;
                netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
                cout<<"Gross Pay: $"<<grosspay<<" \n";                    //outputs what i want
                cout<<"Overtime hours: "<<overtimehours<<" \n";
                cout<<"Social Security: $"<<sstaxt<<" \n";
                cout<<"Federal Income: $"<<fitaxt<<" \n";
                cout<<"State Income: $"<<sstaxt<<" \n";
                cout<<"Union Dues: $10 \n";
                cout<<"Health Insurance: $"<<dependents<<" \n";
                cout<<"Net Pay: $"<<netpay<<" \n";
            }
    
            if(dependnum<=2){        //if you have less than 3 dependents
    
                overtimehours=hours-40;
                overtimerate=16.78/2;
                rate=16.78;
                overtime=overtimehours*overtimerate;
                sstaxt=grosspay*.06;
                fitaxt=grosspay*.14;
                sitaxt=grosspay*.05;
                undues=10;
                grosspay=hours*rate+overtime;
                netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
    
                cout<<"Gross Pay: $"<<grosspay<<" \n";
                cout<<"Overtime hours: "<<overtimehours<<" \n";
                cout<<"Social Security: $"<<sstaxt<<" \n";
                cout<<"Federal Income: $"<<fitaxt<<" \n";
                cout<<"State Income: $"<<sstaxt<<" \n";
                cout<<"Union Dues: $10 \n";
                cout<<"Health Insurance: $0 \n";
                cout<<"Net Pay: $"<<netpay<<" \n";
            }
    
        }
    
    
        if(hours>=41 && dependanswer=="n" ||dependanswer=="N"){        //if overtime & you dont have dependents
    
            overtimehours=hours-40;
            overtimerate=16.78/2;
            rate=16.78;
            overtime=overtimehours*overtimerate;
            sstaxt=grosspay*.06;
            fitaxt=grosspay*.14;
            sitaxt=grosspay*.05;
            undues=10;
            grosspay=hours*rate+overtime;
            netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
            cout<<"Gross Pay: $"<<grosspay<<" \n";
            cout<<"Overtime hours: "<<overtimehours<<" \n";
            cout<<"Social Security: $"<<sstaxt<<" \n";
            cout<<"Federal Income: $"<<fitaxt<<" \n";
            cout<<"State Income: $"<<sstaxt<<" \n";
            cout<<"Union Dues: $10 \n";
            cout<<"Health Insurance: $0 \n";
            cout<<"Net Pay: $"<<netpay<<" \n";
    
        }
    
        if(hours<=40 && dependanswer=="y" || dependanswer=="Y"){        //if no overtime and dependents
    
            cout<<"How many dependents do you have? \n";
            cin>>dependnum;
    
            if(dependnum>=3){        //if you have 3 or more dependents
    
                rate=16.78;
                grosspay=rate*hours;
                sstaxt=grosspay*.06;
                fitaxt=grosspay*.14;
                sitaxt=grosspay*.05;
                undues=10;
                dependents=35;
                netpay=grosspay-sstaxt-fitaxt-sitaxt-undues-dependents;
    
                cout<<"Gross Pay: $"<<grosspay<<" \n";
                cout<<"Overtime hours: 0 \n";
                cout<<"Social Security: $"<<sstaxt<<" \n";
                cout<<"Federal Income: $"<<fitaxt<<" \n";
                cout<<"State Income: $"<<sstaxt<<" \n";
                cout<<"Union Dues: $10 \n";
                cout<<"Health Insurance: $"<<dependents<<" \n";
                cout<<"Net Pay: $"<<netpay<<" \n";
            }
    
            if(dependnum<=2){        //if you have less than 3 dependents
    
    
                rate=16.78;
                grosspay=rate*hours;
                sstaxt=grosspay*.06;
                fitaxt=grosspay*.14;
                sitaxt=grosspay*.05;
                undues=10;
                netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
                cout<<"Gross Pay: $"<<grosspay<<" \n";
                cout<<"Overtime hours: 0 \n";
                cout<<"Social Security: $"<<sstaxt<<" \n";
                cout<<"Federal Income: $"<<fitaxt<<" \n";
                cout<<"State Income: $"<<sstaxt<<" \n";
                cout<<"Union Dues: $10 \n";
                cout<<"Health Insurance: $0 \n";
                cout<<"Net Pay: $"<<netpay<<" \n";
            }
        }
    
        if(hours<=40 &&dependanswer=="n"||dependanswer=="N"){        //if no overtime and no dependents
    
            rate=16.78;
            grosspay=rate*hours;
            sstaxt=grosspay*.06;
            fitaxt=grosspay*.14;
            sitaxt=grosspay*.05;
            undues=10;
            netpay=grosspay-sstaxt-fitaxt-sitaxt-undues;
    
            cout<<"Gross Pay: $"<<grosspay<<" \n";
            cout<<"Overtime hours: 0 \n";
            cout<<"Social Security: $"<<sstaxt<<" \n";
            cout<<"Federal Income: $"<<fitaxt<<" \n";
            cout<<"State Income: $"<<sstaxt<<" \n";
            cout<<"Union Dues: $10 \n";
            cout<<"Health Insurance: $0 \n";
            cout<<"Net Pay: $"<<netpay<<" \n";
    
        }
    
    
    
        system("pause");
        return 0;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    Actually, try and see if your IDE doesn't have an option to format your code. NetBeans has Shift+Alt+F which will format (properly indent, add spaces where needed, and other things that can be specified in formatting options) any selected code in a flash, so I think other IDEs should provide this option too.

    Also, you seem to be using tabs as indentation characters, try switching to spaces only (set your editor to "expand tabs to spaces" and set tab to be 4 spaces).
    Any reasonable editor provides auto-indenting (meaning you press enter, and it adds needed spaces/tabs at the next line) so I actually think writing badly indented code is much harder than "doing it right".

    This is how NB formatted it for me:
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main() {
    
    
        float rate, hours, overtime, overtimerate, undues, overtimehours;
        float dependents, dependnum, netpay, grosspay, sstaxt, fitaxt, sitaxt; //declares variables
        string dependanswer;
    
    
        overtimehours = hours - 40;
        overtimerate = 16.78 / 2;
        rate = 16.78;
        grosspay = rate*hours;
        overtime = overtimehours*overtimerate;
        sstaxt = grosspay * .06;
        fitaxt = grosspay * .14;
        sitaxt = grosspay * .05;
        undues = 10;
        dependents = 35;
    
    
        cout << "How many hours were worked? \n"; //asks how many hours worked
        cin >> hours;
    
        cout << "Do you have any dependents? <Y or N>? \n"; //do yo have dependents
        cin >> dependanswer;
    
        if (hours >= 41 && dependanswer == "y" || dependanswer == "Y") { //if you worked overtime and have dependents
    
            cout << "How many dependents do you have? \n";
            cin >> dependnum;
    
            if (dependnum >= 3) { //if you have 3 or more dependents        
    
                overtimehours = hours - 40;
                overtimerate = 16.78 / 2;
                rate = 16.78;
                overtime = overtimehours*overtimerate;
                sstaxt = grosspay * .06;
                fitaxt = grosspay * .14;
                sitaxt = grosspay * .05;
                undues = 10;
                dependents = 35;
                grosspay = hours * rate + overtime;
                netpay = grosspay - sstaxt - fitaxt - sitaxt - undues - dependents;
    
                cout << "Gross Pay: $" << grosspay << " \n"; //outputs what i want
                cout << "Overtime hours: " << overtimehours << " \n";
                cout << "Social Security: $" << sstaxt << " \n";
                cout << "Federal Income: $" << fitaxt << " \n";
                cout << "State Income: $" << sstaxt << " \n";
                cout << "Union Dues: $10 \n";
                cout << "Health Insurance: $" << dependents << " \n";
                cout << "Net Pay: $" << netpay << " \n";
            }
    
            if (dependnum <= 2) { //if you have less than 3 dependents
    
                overtimehours = hours - 40;
                overtimerate = 16.78 / 2;
                rate = 16.78;
                overtime = overtimehours*overtimerate;
                sstaxt = grosspay * .06;
                fitaxt = grosspay * .14;
                sitaxt = grosspay * .05;
                undues = 10;
                grosspay = hours * rate + overtime;
                netpay = grosspay - sstaxt - fitaxt - sitaxt - undues;
    
    
                cout << "Gross Pay: $" << grosspay << " \n";
                cout << "Overtime hours: " << overtimehours << " \n";
                cout << "Social Security: $" << sstaxt << " \n";
                cout << "Federal Income: $" << fitaxt << " \n";
                cout << "State Income: $" << sstaxt << " \n";
                cout << "Union Dues: $10 \n";
                cout << "Health Insurance: $0 \n";
                cout << "Net Pay: $" << netpay << " \n";
            }
    
        }
    
    
        if (hours >= 41 && dependanswer == "n" || dependanswer == "N") { //if overtime & you dont have dependents
    
            overtimehours = hours - 40;
            overtimerate = 16.78 / 2;
            rate = 16.78;
            overtime = overtimehours*overtimerate;
            sstaxt = grosspay * .06;
            fitaxt = grosspay * .14;
            sitaxt = grosspay * .05;
            undues = 10;
            grosspay = hours * rate + overtime;
            netpay = grosspay - sstaxt - fitaxt - sitaxt - undues;
    
            cout << "Gross Pay: $" << grosspay << " \n";
            cout << "Overtime hours: " << overtimehours << " \n";
            cout << "Social Security: $" << sstaxt << " \n";
            cout << "Federal Income: $" << fitaxt << " \n";
            cout << "State Income: $" << sstaxt << " \n";
            cout << "Union Dues: $10 \n";
            cout << "Health Insurance: $0 \n";
            cout << "Net Pay: $" << netpay << " \n";
    
        }
    
        if (hours <= 40 && dependanswer == "y" || dependanswer == "Y") { //if no overtime and dependents
    
            cout << "How many dependents do you have? \n";
            cin >> dependnum;
    
            if (dependnum >= 3) { //if you have 3 or more dependents
    
                rate = 16.78;
                grosspay = rate*hours;
                sstaxt = grosspay * .06;
                fitaxt = grosspay * .14;
                sitaxt = grosspay * .05;
                undues = 10;
                dependents = 35;
                netpay = grosspay - sstaxt - fitaxt - sitaxt - undues - dependents;
    
                cout << "Gross Pay: $" << grosspay << " \n";
                cout << "Overtime hours: 0 \n";
                cout << "Social Security: $" << sstaxt << " \n";
                cout << "Federal Income: $" << fitaxt << " \n";
                cout << "State Income: $" << sstaxt << " \n";
                cout << "Union Dues: $10 \n";
                cout << "Health Insurance: $" << dependents << " \n";
                cout << "Net Pay: $" << netpay << " \n";
            }
    
            if (dependnum <= 2) { //if you have less than 3 dependents
    
    
                rate = 16.78;
                grosspay = rate*hours;
                sstaxt = grosspay * .06;
                fitaxt = grosspay * .14;
                sitaxt = grosspay * .05;
                undues = 10;
                netpay = grosspay - sstaxt - fitaxt - sitaxt - undues;
    
                cout << "Gross Pay: $" << grosspay << " \n";
                cout << "Overtime hours: 0 \n";
                cout << "Social Security: $" << sstaxt << " \n";
                cout << "Federal Income: $" << fitaxt << " \n";
                cout << "State Income: $" << sstaxt << " \n";
                cout << "Union Dues: $10 \n";
                cout << "Health Insurance: $0 \n";
                cout << "Net Pay: $" << netpay << " \n";
            }
        }
    
        if (hours <= 40 && dependanswer == "n" || dependanswer == "N") { //if no overtime and no dependents
    
            rate = 16.78;
            grosspay = rate*hours;
            sstaxt = grosspay * .06;
            fitaxt = grosspay * .14;
            sitaxt = grosspay * .05;
            undues = 10;
            netpay = grosspay - sstaxt - fitaxt - sitaxt - undues;
    
            cout << "Gross Pay: $" << grosspay << " \n";
            cout << "Overtime hours: 0 \n";
            cout << "Social Security: $" << sstaxt << " \n";
            cout << "Federal Income: $" << fitaxt << " \n";
            cout << "State Income: $" << sstaxt << " \n";
            cout << "Union Dues: $10 \n";
            cout << "Health Insurance: $0 \n";
            cout << "Net Pay: $" << netpay << " \n";
    
        }
    
    
    
        system("pause");
        return 0;
    }
    Now, isn't that a lot more readable.

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Quote Originally Posted by Xupicor View Post
    Also, you seem to be using tabs as indentation characters, try switching to spaces only (set your editor to "expand tabs to spaces" and set tab to be 4 spaces).
    Absolute nonsense. Tabs are not some evil things as you make it out to be.
    One has to pick the choice one is most comfortable with.
    Some editors, like Visual Studio, allowed you to actually work with tabs, but when you copy the code, the tabs are replaced with spaces.
    Regardless, tabs are not evil.

    Now, isn't that a lot more readable.
    Is that a question or a statement?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    Quote Originally Posted by Elysia View Post
    Absolute nonsense.
    What is the nonsense, that rfoor uses tabs?
    Quote Originally Posted by Elysia View Post
    Tabs are not some evil things as you make it out to be.
    I never wrote anything about tabs being evil, I merely suggested to try spaces, without any rant about it at all. Not nearly as dramatic as you make it out to be.

    Quote Originally Posted by Elysia View Post
    One has to pick the choice one is most comfortable with.
    Some editors, like Visual Studio, allowed you to actually work with tabs, but when you copy the code, the tabs are replaced with spaces.
    Regardless, tabs are not evil.
    Again, never said they were, albeit I still prefer spaces, since they are more portable, even if take up a bit more... space. Don't you find it a bit ironic though, that VS changes the tabs to spaces on copy?

    Quote Originally Posted by Elysia View Post
    Is that a question or a statement?
    Actually, that would be a figure of speech, a rhetorical question, which does not need to be punctuated by a question mark.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,450
    Quote Originally Posted by Xupicor View Post
    I never wrote anything about tabs being evil, I merely suggested to try spaces, without any rant about it at all. Not nearly as dramatic as you make it out to be.
    You suggested switching over to spaces instead of tabs.

    Actually, that would be a figure of speech, a rhetorical question, which does not need to be punctuated by a question mark.
    There is no such thing as a question without a question mark. Then it is a statement.
    So, I figure you meant it to be a statement.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Salary Range Calculator help please!! =(
    By bambino in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2006, 06:17 PM
  2. finally my salary program but...........
    By pancho in forum C Programming
    Replies: 11
    Last Post: 02-02-2002, 10:28 PM
  3. salary program heeeelp!
    By pancho in forum C Programming
    Replies: 6
    Last Post: 02-02-2002, 07:56 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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