This is a program we had to do for class, and it works just fine but I get a curious error message.
payroll.cpp(57) : warning C4551: function call missing argument list
To save you the trouble of having to count The line it's complaining about is in red, it's the payroll.close line.
Why am I getting this error, anyone know?
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
void createPayroll();
void createReport();
int main()
{
char ans;
createPayroll();
cout << "\n\nCreate Payroll Report? <y or n>";
cin >> ans;
if (ans == 'y')
{
createReport();
cout << "\nReport has been created\n";
}
return 0;
}
void createPayroll()
{
int empNum;
double hours, payRate;
ofstream payroll;
payroll.open("payroll.txt", ios::app);
if (payroll.fail())
{
cout << "Error opening output file." << endl;
exit(1);
}
cout << "Enter Employee Number (0 to quit): ";
cin >> empNum;
while (empNum > 0)
{
cout << "Enter Hours Worked: ";
cin >> hours;
cout << "Enter Pay Rate: ";
cin >> payRate;
payroll << empNum << " " << hours << " " << payRate << endl;
cout << "\n\nA record has been added.\n";
cout << "Enter Employee Number (0 to quit): ";
cin >> empNum;
}
payroll.close;
}
void createReport()
{
int empNum;
double hours, payRate, pay;
ifstream payroll;
ofstream report;
payroll.open("payroll.txt");
report.open("report.txt", ios::app);
if (payroll.fail())
{
cout << "Error opening input file.";
exit(1);
}
if (report.fail())
{
cout << "Error opening output file.";
exit(1);
}
report.setf(ios::fixed);
report.setf(ios::showpoint);
report.precision(2);
report << "Emp Number" << setw(12) << "Hours" << setw(12) << "Pay Rate" << setw(12) << "Pay" << endl;
while (payroll >> empNum >> hours >> payRate)
{
if (hours > 40)
{
pay = (((hours - 40) * payRate) * 1.5) + 40 * payRate;
}
else
{
pay = hours * payRate;
}
report << empNum << setw(18) << hours << setw(12) << payRate << setw(12) << pay << endl;
}
}