Outfile not writing to txt
Dec 5, 2017 at 6:50am UTC
I'm trying to produce an output file named 'emp_data.txt' containing results from the following functions:
output_payroll_data
and
output_payroll_summary
https://github.com/ashley51/payroll_prog/blob/master/Lab14_Payroll.cpp
From what I understand, replacing 'std::cout' with 'outfile' for the lines I would like to be written on the text file should produce the result that I need.
But upon ending the program, the text file remains blank.
I most likely understood it wrong...
But doing a single line like:
outfile << full_name << " " << hours << " " << hourly_rate << std::endl;
Writes to the text file.
Last edited on Dec 5, 2017 at 7:09am UTC
Dec 5, 2017 at 8:47am UTC
Here's one way to do it:
Prototypes:
1 2 3 4 5 6 7 8
void output_payroll_data (std::string full_name, double regular_hours, double overtime_hours,
double hourly_rate, double gross_pay, double tax, double deductions,
double net_pay, std::ostream & out = std::cout );
void output_payroll_summary(int num_emps, std::string emp_names[],
double emp_grosses[], double total_gross_pay,
double ave_gross_pay, double min_gross_pay,
double max_gross_pay, std::ostream& out = std::cout );
Function definitions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
void output_payroll_data (std::string full_name, double regular_hours, double overtime_hours,
double hourly_rate, double gross_pay, double tax, double deductions,
double net_pay, std::ostream & out )
{
out << std::endl;
out << "12345678901234567890##21.00##21.00##321.00"
<< "##4321.00##321.00##321.00##4321.00" << std::endl;
out << " Reg. Ovt. Hourly"
<< " Gross Net " << std::endl;
out << "Name Hours Hours Rate "
<< " Pay Taxes Deduct Pay " << std::endl;
out << "==================== ===== ===== ======"
<< " ======= ====== ====== =======" << std::endl;
out << std::left << std::setw(20) << full_name << " " ;
out << std::right;
out << std::setw(5) << regular_hours << " " ;
out << std::setw(5) << overtime_hours << " " ;
out << std::setw(6) << hourly_rate << " " ;
out << std::setw(7) << gross_pay << " " ;
out << std::setw(6) << tax << " " ;
out << std::setw(6) << deductions << " " ;
out << std::setw(7) << net_pay << std::endl << std::endl;
}
and similarly for the other function.
Then when calling the function from main(), this will output to console as at present:
1 2
output_payroll_data (full_name, regular_hours, overtime_hours,
hourly_rate, gross_pay, tax, deductions, net_pay);
and/or this to output to the file
1 2
output_payroll_data (full_name, regular_hours, overtime_hours,
hourly_rate, gross_pay, tax, deductions, net_pay, outfile );
Dec 5, 2017 at 6:28pm UTC
Thanks for the response.
Topic archived. No new replies allowed.