11 Replies - 494 Views - Last Post: 07 October 2012 - 04:33 PM Rate Topic: -----

#1 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

How do I properly use a file for input and create an output

Posted 06 October 2012 - 02:17 PM

I have tried using the various fstream options and have looked through my book and searched forums but for some reason the solution evades me. I am so receiving errors with my overtime code in my payroll program, I am just trying to get pointed in the right direction, once it is clear then I should have no problems with getting my code to work. I am after all just adding another tax, overtime calculation, and file input and output instead of user input to a program that previously worked. Any help is greatly appreciated. I did think the fout with cout is odd, but I remember the professor saying that fout duplicates cout but to a file.

#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
using namespace std;



int main()
{ 
        

	
	    // Reads input from file
	     fstream file;
	     file.open("program3input.txt");
	     

		// Define Constants
		 const double FICAPERCENTAGE = 0.0765;
		 const double FEDERALTAX = 0.1500;
		 const double INCOMETAX = 0.0300;
	
		// Define Variables
		 int employeeNumber;
		 double hourlyRate;
		 int hoursWorked;
		 double normalPay;
		 double overtime;
		 double overtimePay;
		
		 
		 // Dispays time and date function
		 time_t sysTime;
		 time (&sysTime);
		
		 //Calculate gross and net pay
		 
         double grossPay = static_cast<double>(hoursWorked) * hourlyRate + overtimePay * overtime;
		 double overtime = hoursWorked - 40;
	     double overtimePay = (hoursWorked - 40)* (normalPay * 1.5)+ (40 * normalPay);
         double ficaDeduction = grossPay * FICAPERCENTAGE;
		 double federalTax = grossPay * FEDERALTAX;
		 double incomeTax = grossPay * INCOMETAX;
		 double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
		 double totalDeduction = ficaDeduction + federalTax + incomeTax;

		 /*Print employee number, hourly rate, hours worked, total gross pay, FICA
		 and Federal deduction, along with Net pay								*/

		 fout.open ("program3output.txt");
		 cout << fixed << setprecision(2); // Sets output at 2 decimal places
		 cout << endl;
		 fout << fixed << setprecision(2); // Sets output at 2 decimal places
		 fout << endl;
		 cout << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		 fout << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		 cout << "The current local date/time: " <<ctime(&sysTime);
		 fout << "The current local date/time: " <<ctime(&sysTime);
		 cout << "---------------------------------------------------------" << endl;
		 fout << "---------------------------------------------------------" << endl;
		 cout << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		 fout << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		 cout << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		 fout << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		 cout << "Regular Hours worked:       " << setw(10)  << hoursWorked << endl;
		 fout << "Regular Hours worked:       " << setw(10)  << hoursWorked << endl;
		 cout << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		 fout << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		 cout << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		 fout << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		 cout << "Deductions:         " << setw(14)  << endl;
		 fout << "Deductions:         " << setw(14)  << endl;
		 cout << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		 fout << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		 cout << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		 fout << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		 cout << "---------------------------------------------------------" << endl;
		 fout << "---------------------------------------------------------" << endl;
		 cout << "Total Deductions:                  $  " << setw(8) << totalDeduction << endl;
		 fout << "Total Deductions:                  $  " << setw(8) << totalDeduction << endl;
		 cout << "                                                   ======" << endl;
		 fout << "                                                   ======" << endl;
		 cout << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		 fout << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		 cout << "---------------------------------------------------------" << endl;
		 fout << "---------------------------------------------------------" << endl;      
		 return 0;
}


My errors

1>------ Build started: Project: Program3, Configuration: Debug Win32 ------
1>Build started 10/6/2012 4:16:39 PM.
1>InitializeBuildStatus:
1> Touching "Debug\Program3.unsuccessfulbuild".
1>ClCompile:
1> Program3.cpp
1>f:\program3\program3\program3.cpp(46): error C2086: 'double overtime' : redefinition
1> f:\program3\program3\program3.cpp(35) : see declaration of 'overtime'
1>f:\program3\program3\program3.cpp(47): error C2086: 'double overtimePay' : redefinition
1> f:\program3\program3\program3.cpp(36) : see declaration of 'overtimePay'
1>f:\program3\program3\program3.cpp(57): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(57): error C2228: left of '.open' must have class/struct/union
1> type is ''unknown-type''
1>f:\program3\program3\program3.cpp(60): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(61): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(61): error C2563: mismatch in formal parameter list
1>f:\program3\program3\program3.cpp(61): error C2568: '<<' : unable to resolve function overload
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1021): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=unsigned short,
1> _Traits=std::char_traits<unsigned short>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1011): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(1003): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(977): or 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1>f:\program3\program3\program3.cpp(63): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(65): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(67): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(69): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(71): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(73): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(75): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(77): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(79): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(81): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(83): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(85): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(87): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(89): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(91): error C2065: 'fout' : undeclared identifier
1>f:\program3\program3\program3.cpp(93): error C2065: 'fout' : undeclared identifier
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.02
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Is This A Good Question/Topic? 0
  • +

Replies To: How do I properly use a file for input and create an output

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,396
  • Joined: 19-February 09

Re: How do I properly use a file for input and create an output

Posted 06 October 2012 - 03:09 PM

Here you create a variable.

21         double overtime;



Then you try and recreate the variable, and the compiler complains. So just remove the double from here.

32         double overtime = hoursWorked - 40;


Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: How do I properly use a file for input and create an output

Posted 06 October 2012 - 03:29 PM

And where have you defined a stream variable named fout?

These errors really are self-explanatory.
Was This Post Helpful? 0
  • +
  • -

#4 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 06 October 2012 - 03:45 PM

I apologize, but this is an intro to c++ and the teacher jumped from chapter 3 to chapter 13 with input/output with files and it threw me off.

View Post#define, on 06 October 2012 - 03:09 PM, said:

Here you create a variable.

21         double overtime;



Then you try and recreate the variable, and the compiler complains. So just remove the double from here.

32         double overtime = hoursWorked - 40;



Thank you, this helped and does make sense, now if only I could get my input/output from and to a file working.
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,396
  • Joined: 19-February 09

Re: How do I properly use a file for input and create an output

Posted 06 October 2012 - 07:52 PM

Hi you need to create a file stream object called fout, before it is opened here.

43         fout.open ("program3output.txt");




It is easiest to automatically create an output file stream object/variable with ofstream.

ofstream fout; 


Was This Post Helpful? 1
  • +
  • -

#6 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 02:35 PM

Thank you, that did help and I now I am getting the numbers I entered into the program3input.txt file on the command line. 21459.2 is displaying but what is typed in the file is one line 21 45 9.2 . which is supposed to be ID, hours, and hourly. I am just somehow not getting the calculations or editing, I am also getting a run time check error #3 the variable 'overtimePay' is being used without being initialized. I thought I had declared and initialized all of my variables. Any help is definitely appreciated, as I have googled this issue, and when I followed the instructions in my book I wasn't getting any output to the command line.



#include <iomanip>
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>

using namespace std;



int main()
{



// Define Constants
const double FICAPERCENTAGE = 0.0765;
const double FEDERALTAX = 0.1500;
const double INCOMETAX = 0.0300;

// Define Variables
int employeeNumber;
double hourlyRate;
int hoursWorked;
double overtime;
double overtimePay;
double grossPay;


// Dispays time and date function
time_t sysTime;
time (&sysTime);

// Read data
ifstream input("program3input.txt");
employeeNumber;
hoursWorked;
hourlyRate;
input >> employeeNumber >> hoursWorked >> hourlyRate;
cout << employeeNumber << hoursWorked << hourlyRate;

input.close();

//Calculate gross and net pay

grossPay = hoursWorked * hourlyRate + overtimePay;
overtime = hoursWorked - 40;
overtimePay = overtime * (hourlyRate * 1.5);
double ficaDeduction = grossPay * FICAPERCENTAGE;
double federalTax = grossPay * FEDERALTAX;
double incomeTax = grossPay * INCOMETAX;
double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
double totalDeduction = ficaDeduction + federalTax + incomeTax;

cout << fixed << setprecision(2); // Sets output at 2 decimal places
cout << endl;
cout << "Joe's Hardware Payroll Program" << setw(5) << endl;
cout << "The current local date/time: " <<ctime(&sysTime);
cout << "---------------------------------------------------------" << endl;
cout << "Employee Number: " << setw(10) << employeeNumber << endl << endl;
cout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl;
cout << "Regular Hours worked: " << setw(10) << hoursWorked << endl;
cout << "Overtime Hours Worked: " << setw(10) << overtime << endl;
cout << "Total Gross Pay: $ " << setw(4) << grossPay << endl;
cout << "Deductions: " << setw(14) << endl;
cout << "FICA: $ " << setw(8) << ficaDeduction << endl;
cout << "Federal Tax: $ " << setw(8) << federalTax << endl;
cout << "---------------------------------------------------------" << endl;
cout << "Total Deductions: $ " << setw(8) << totalDeduction << endl;
cout << " ======" << endl;
cout << "Net Pay: $ " << setw(6) << netPay << endl;
cout << "---------------------------------------------------------" << endl;

// Output data
ofstream fout;

fout.open ("program3output.txt");
// Edits lines of code
fout << fixed << setprecision(2);
fout << endl;
fout << "Joe's Hardware Payroll Program" << setw(5) << endl;
fout << "The current local date/time: " <<ctime(&sysTime);
fout << "---------------------------------------------------------" << endl;
fout << "Employee Number: " << setw(10) << employeeNumber << endl << endl;
fout << "Hourly rate of pay: $ " << setw(6) << hourlyRate << endl;
fout << "Regular Hours worked: " << setw(10) << hoursWorked << endl;
fout << "Overtime Hours Worked: " << setw(10) << overtime << endl;
fout << "Total Gross Pay: $ " << setw(4) << grossPay << endl;
fout << "Deductions: " << setw(14) << endl;
fout << "FICA: $ " << setw(8) << ficaDeduction << endl;
fout << "Federal Tax: $ " << setw(8) << federalTax << endl;
fout << "---------------------------------------------------------" << endl;
fout << "Total Deductions: $ " << setw(8) << totalDeduction << endl;
fout << " ======" << endl;
fout << "Net Pay: $ " << setw(6) << netPay << endl;
fout << "---------------------------------------------------------" << endl;

fout.close();
return 0;
}



Sorry, let me try putting that code in again.

#include <iomanip>
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>

using namespace std;



int main()
{ 


		
	     // Define Constants
		 const double FICAPERCENTAGE = 0.0765;
		 const double FEDERALTAX = 0.1500;
		 const double INCOMETAX = 0.0300;
	
		// Define Variables
		 int employeeNumber;
		 double hourlyRate;
		 int hoursWorked;
		 double overtime;
		 double overtimePay;
		 double grossPay;
		
		 
		 // Dispays time and date function
		 time_t sysTime;
		 time (&sysTime);
		
	     // Read data
ifstream input("program3input.txt");		
		employeeNumber;
		hoursWorked;
		hourlyRate;
		input >> employeeNumber >> hoursWorked >> hourlyRate;
		cout <<  employeeNumber << hoursWorked << hourlyRate;
		
		input.close();

		 //Calculate gross and net pay
		 
         grossPay = hoursWorked * hourlyRate + overtimePay;
		 overtime = hoursWorked - 40;
	     overtimePay = overtime * (hourlyRate * 1.5);
         double ficaDeduction = grossPay * FICAPERCENTAGE;
		 double federalTax = grossPay * FEDERALTAX;
		 double incomeTax = grossPay * INCOMETAX;
		 double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
		 double totalDeduction = ficaDeduction + federalTax + incomeTax;
		
		 cout << fixed << setprecision(2); // Sets output at 2 decimal places
		 cout << endl;
	     cout << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		 cout << "The current local date/time: " <<ctime(&sysTime);
		 cout << "---------------------------------------------------------" << endl;
		 cout << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		 cout << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		 cout << "Regular Hours worked:       " << setw(10)  << hoursWorked << endl;
		 cout << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		 cout << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		 cout << "Deductions:         " << setw(14)  << endl;
		 cout << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		 cout << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		 cout << "---------------------------------------------------------" << endl;
		 cout << "Total Deductions:                  $  " << setw(8) << totalDeduction << endl;
		 cout << "                                                   ======" << endl;
		 cout << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		 cout << "---------------------------------------------------------" << endl;
		 
		 // Output data
ofstream fout;
		
		fout.open ("program3output.txt");
		// Edits lines of code
		fout << fixed << setprecision(2);
		fout << endl;
		fout << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		fout << "The current local date/time: " <<ctime(&sysTime);
		fout << "---------------------------------------------------------" << endl;
		fout << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		fout << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		fout << "Regular Hours worked:       " << setw(10)  << hoursWorked << endl;
		fout << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		fout << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		fout << "Deductions:         " << setw(14)  << endl;
		fout << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		fout << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		fout << "---------------------------------------------------------" << endl;
		fout << "Total Deductions:                  $  " << setw(8) << totalDeduction << endl;
		fout << "                                                   ======" << endl;
		fout << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		fout << "---------------------------------------------------------" << endl;

		fout.close();
		 return 0;
}


Was This Post Helpful? 0
  • +
  • -

#7 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 02:42 PM

For your overtimePay error. Look at lines 46 & 48. Pretty clear answer.

Happy Coding

EDIT: was looking at original post.

This post has been edited by jdavi134: 07 October 2012 - 02:43 PM

Was This Post Helpful? 1
  • +
  • -

#8 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 02:58 PM

View Postjdavi134, on 07 October 2012 - 02:42 PM, said:

For your overtimePay error. Look at lines 46 & 48. Pretty clear answer.

Happy Coding

EDIT: was looking at original post.


Thank you!!!! Thank you!!!! It is working, now I just have to make sure the math is right, you are a genius! I wish I could ship you a beer lol.

Only issue now is the output isn't correct :( , I am almost done though, thank you everyone for your help.


21459.2
Joe's Hardware Payroll Program
The current local date/time: Sun Oct 07 16:56:11 2012
---------------------------------------------------------
Employee Number: 21

Hourly rate of pay: $ 9.20
Regular Hours worked: 45
Overtime Hours Worked: 5.00
Total Gross Pay: $ 483.00
Deductions:
FICA: $ 36.95
Federal Tax: $ 72.45
---------------------------------------------------------
Total Deductions: $ 123.89
======
Net Pay: $ 359.11
---------------------------------------------------------
Press any key to continue . . .
Was This Post Helpful? 0
  • +
  • -

#9 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 03:11 PM

I realized that I needed to delete line 40 to get rid of the numbers jumbled together on output. Do I have to create an Else If statement to get my overtime and regular pay to calculate correctly?
Was This Post Helpful? 0
  • +
  • -

#10 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 04:07 PM

I got it working with proper output, thank you all, the code I had to fix

overtime = hoursWorked - 40;
	     overtimePay = hourlyRate * 1.5;
         grossPay = (hoursWorked - overtime) * hourlyRate + overtime * overtimePay;
		 double ficaDeduction = grossPay * FICAPERCENTAGE;
		 double federalTax = grossPay * FEDERALTAX;
		 double incomeTax = grossPay * INCOMETAX;
		 double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
		 double totalDeduction = ficaDeduction + federalTax + incomeTax;



Joe's Hardware Payroll Program
The current local date/time: Sun Oct 07 18:02:12 2012
---------------------------------------------------------
Employee Number: 21

Hourly rate of pay: $ 9.20
Regular Hours worked: 45
Overtime Hours Worked: 5
Total Gross Pay: $ 437.00
Deductions:
FICA: $ 33.43
Federal Tax: $ 65.55
Income Tax: $ 13.11
---------------------------------------------------------
Total Deductions: $ 112.09
======
Net Pay: $ 324.91
---------------------------------------------------------

I spoke too soon, I see I have 45 regular hours and 5 hours of overtime when anything over 40 is considered overtime, any suggestions?
Was This Post Helpful? 0
  • +
  • -

#11 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 04:25 PM

Well if your hoursWorked variable is representing only the regular hours that were worked, wouldn't you want to set it to that? If you worked 45 total hours, and you found out that 5 of those hours were overtime, wouldn't you want to separate the 2 different amounts of hours?
Was This Post Helpful? 0
  • +
  • -

#12 Stuckincode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 05-October 12

Re: How do I properly use a file for input and create an output

Posted 07 October 2012 - 04:33 PM

Ok, I figured it out, I just needed to add - overtime on lines 62 and 86.

Hope i'm not posting the code too many times, but this is my final coding before proper comments are added.

#include <iomanip>
#include <iostream>
#include <ctime>
#include <fstream>
#include <string>

using namespace std;



int main()
{ 


		
	     // Define Constants
		 const double FICAPERCENTAGE = 0.0765;
		 const double FEDERALTAX = 0.1500;
		 const double INCOMETAX = 0.0300;
	
		// Define Variables
		 int employeeNumber;
		 double hourlyRate;
		 int hoursWorked;
		 int overtime;
		 double overtimePay;
		 double grossPay;
		
		 
		 // Dispays time and date function
		 time_t sysTime;
		 time (&sysTime);
		
	    // Read data
ifstream input("program3input.txt");		
	    employeeNumber;
		hoursWorked;
		hourlyRate;
		input >> employeeNumber >> hoursWorked >> hourlyRate;
		
		
		input.close(); 

		 //Calculate gross and net pay
		 
         
		 overtime = hoursWorked - 40;
	     overtimePay = hourlyRate * 1.5;
         grossPay = (hoursWorked - overtime) * hourlyRate + overtime * overtimePay;
		 double ficaDeduction = grossPay * FICAPERCENTAGE;
		 double federalTax = grossPay * FEDERALTAX;
		 double incomeTax = grossPay * INCOMETAX;
		 double netPay = grossPay - ficaDeduction - federalTax - incomeTax;
		 double totalDeduction = ficaDeduction + federalTax + incomeTax;
		
		 cout << fixed << setprecision(2); // Sets output at 2 decimal places
		 cout << endl;
	     cout << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		 cout << "The current local date/time: " <<ctime(&sysTime);
		 cout << "---------------------------------------------------------" << endl;
		 cout << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		 cout << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		 cout << "Regular Hours worked:       " << setw(10)  << hoursWorked - overtime << endl;
		 cout << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		 cout << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		 cout << "Deductions:         " << setw(14)  << endl;
		 cout << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		 cout << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		 cout << "Income Tax:                       $  " << setw(8) << incomeTax << endl;
		 cout << "---------------------------------------------------------" << endl;
		 cout << "Total Deductions:                 $  " << setw(8) << totalDeduction << endl;
		 cout << "                                                   ======" << endl;
		 cout << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		 cout << "---------------------------------------------------------" << endl;
		 
		 // Output data
ofstream output;
		
		output.open ("program3output.txt");
		// Edits lines of code
		output << fixed << setprecision(2);
		output << endl;
		output << "Joe's Hardware Payroll Program" <<  setw(5) << endl;
		output << "The current local date/time: " <<ctime(&sysTime);
		output << "---------------------------------------------------------" << endl;
		output << "Employee Number:    " << setw(10)  << employeeNumber << endl << endl;
		output << "Hourly rate of pay:                             $  " << setw(6) << hourlyRate << endl;
		output << "Regular Hours worked:       " << setw(10)  << hoursWorked - overtime << endl;
		output << "Overtime Hours Worked:      " << setw(10)  << overtime    << endl;
		output << "Total Gross Pay:                                $  " << setw(4) << grossPay << endl;
		output << "Deductions:         " << setw(14)  << endl;
		output << "FICA:                             $  " << setw(8) << ficaDeduction << endl;
		output << "Federal Tax:                      $  " << setw(8) << federalTax << endl;
		output << "Income Tax:                       $  " << setw(8) << incomeTax << endl;
		output << "---------------------------------------------------------" << endl;
		output << "Total Deductions:                 $  " << setw(8) << totalDeduction << endl;
		output << "                                                   ======" << endl;
		output << "Net Pay:                                        $  " << setw(6) << netPay << endl;
		output << "---------------------------------------------------------" << endl;

		output.close();
		 return 0;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1