Thread: help with accumulating in payroll program

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    help with accumulating in payroll program

    Code:
    ////////////////////////////////////////////////////
    // Daniel Pritchett
    // COP1220
    // Payroll Program made to generate
    // payroll report based on employee information
    // Made with Visual C++.NET
    ////////////////////////////////////////////////////
    
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <fstream>
    
    using namespace std;
    double overtimeGross(int, double, double);
    double federalTax(int, double);
    
    int main()
    {
    	string EmployeeFirstName, EmployeeLastName, EmployeeNumber;
    	int Dependents, HoursWorked, Workers, WorkersSave;						
    	double HourlyRate, GrossPay, RegPay, FedTax, NetPay, Overtime;
    	double Total_RegPay, Total_Overtime, Total_GrossPay, Total_FedTax, Total_NetPay; 
    	ofstream outFile;
    
    	//output of heading to file
    	outFile.open("a:test.txt");
    	outFile << fixed;
    	outFile <<"EMPLOYEEE" << setw(16) << "EMPLOYEE" << setw(10) << "REG" << setw(16) 
    	   << "OVERTIME" << setw(14) << "GROSS" << setw(9) << "FED"
     << setw(11) << "NET" <<endl;  
    	outFile <<"NUMBER" << setw(15) << "NAME" << setw(14) << "PAY" 
    		    << setw(11) << "PAY"
     << setw(17) << "PAY" << setw(11) << "TAX" << setw(11) << "PAY" << endl << endl;
    
    	cout << "How many employees are you going to enter in the payroll? ";
    	cin >> Workers;
    
    	//saves worker number for use in the end.
    	WorkersSave = Workers;
    
    	Total_RegPay = 0;
    	Total_Overtime = 0;
    	Total_GrossPay = 0;
    	Total_FedTax = 0;
    	Total_NetPay = 0;
    	//for loop runs as long as Workers does not equal 0
    	for( ; Workers!=0 ; Workers--)
    	{
    		
    		cout << "\nEnter the Employee's six digit work Number: ";
    		cin >> EmployeeNumber;
    		cout << "Enter the employees first and last name: ";
    		cin >> EmployeeFirstName >> EmployeeLastName;
    		cout << "Enter the number of Dependents: ";
    		cin >> Dependents;
    		cout << "Enter your Hourly Rate: $";
    		cin >> HourlyRate;
    		cout << "Enter the numbers of hours woked: ";
    		cin >> HoursWorked;
    		RegPay = HourlyRate * HoursWorked;
    
    		//goes into outfile, change cout to outFile
    		outFile << right << EmployeeNumber  
    			 << setw(9) << EmployeeFirstName<< " " << EmployeeLastName
    			 << setw(6) << right << setprecision(2)<< "$" << RegPay;
    
    		//condition for overtime	 
    		if(HoursWorked > 40)
    		{	
    			Overtime =  overtimeGross(HoursWorked, HourlyRate, RegPay);
    			outFile << setw(9) << right << setprecision(2)<< "$" << Overtime;
    			GrossPay = Overtime + RegPay;
    			
    		}
    			else
    			{ 
    				Overtime = 0;
    				GrossPay = RegPay;
    				outFile << setw(12) << right <<setprecision(2)
     << "$" << Overtime;
    				
    			}
    
    		outFile << setw(9) << right << "$" << setprecision(2) << GrossPay;
    		
    		//calculating federal tax
    		FedTax = federalTax(Dependents, GrossPay);
    		outFile << setw(5) << right << "$" << setprecision(2) << FedTax;
    
    		//calculating net pay
    		NetPay = GrossPay - FedTax;
    		outFile << setw(5) <<right << "$" << setprecision(2) << NetPay << endl;
    	
    
    		Total_RegPay += RegPay;
    		Total_Overtime += Overtime;
    		Total_GrossPay += GrossPay;
    		Total_FedTax += FedTax;
    		Total_NetPay += NetPay;
    
    	//end of for loop
    	}
    
    	outFile <<"\n\n"<< setw(25) <<setprecision(2)<< "TOTAL:" << setw(6) << "$" 
    << Total_RegPay << setw(8) << "$" << Total_Overtime << setw(10)
    		<< "$" 
    << Total_GrossPay << setw(6) << "$" << Total_FedTax << setw(7) << "$" <<  Total_NetPay;
    	return 0;
    }
    
    double overtimeGross(int HoursWorked, double HourlyRate, double RegPay)
    {
    	return (HoursWorked - 40) * (HourlyRate * 1.5);  
    }
    
    double federalTax(int Dependents, double GrossPay)
    {
    	return (GrossPay - (Dependents * 42.15)) * .20;
    
    }
    see inquiry belowat bottom
    Last edited by indigo0086; 10-15-2002 at 09:10 PM.

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    the only thing is, before I do the
    Total_X += Total_X;
    I have to assighn total_x to the first gross amount, but then it wouldnt' really work because everytime it loops, it will just re-assign the value of the Total_X. You understand?

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by indigo0086
    the only thing is, before I do the
    Total_X += Total_X;
    I have to assighn total_x to the first gross amount, but then it wouldnt' really work because everytime it loops, it will just re-assign the value of the Total_X. You understand?
    Well, if you initalise Total_X to 0 before the loop, then use something like this:
    >Total_X += OnePersons_X;
    ... it will added up as you go through the loop, then you just cout Total_X at the end.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    oh I get you so it would be something like
    Code:
    //for loop
    {
    
    OneTotalGross = Gross_Pay
    Total_Gross += OneTotalGross
    }

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Yeah, something like that. See what you come up with.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    okay, above is my newly made. Everything is set exept the output has to be formatted so that they are evenly columned. How would What is the best way using basic formatting methods to ouput the format in even columns. Right Justified btw.

  7. #7
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Lightbulb

    EUREKA! I finally finished it. SOrry for the messy code but that's what I was working with. I just wish there was an easier way for me to output information other than trial and error. Doh, forgot to mention thankx hammer for your help. Now I have to write the pseudocode for the prog cuz our teacher requires it ;(
    Last edited by indigo0086; 10-15-2002 at 09:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM