It works just fine but

This is a discussion on It works just fine but within the C++ Programming forums, part of the General Programming Boards category; This is a program we had to do for class, and it works just fine but I get a curious ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    9

    It works just fine but

    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;
    	}
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    close is a function (to be specific, it's a member function of a class, and payroll is an instance of that class). Function calls always have a set of parentheses after them - even if there are no arguments. Add that empty set of parentheses and you're good to go.

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    its suppose to be
    Code:
    payroll.close();


    EDIT: sean you must've answered just a sec before me! lol

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    Ah ha!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Works on PC, not on UNIX
    By Decrypt in forum C++ Programming
    Replies: 14
    Last Post: 04-20-2006, 01:13 PM
  2. Program works on Windows XP and 2000, not on 98 or ME
    By MidnightlyCoder in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 02:36 PM
  3. Why <complete program> doesn't works right?
    By Gamer_Jimbo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2006, 01:28 AM
  4. Wont run in X, works fine in alt+F1 terminal
    By zmerlinz in forum Linux Programming
    Replies: 5
    Last Post: 04-28-2004, 11:58 AM
  5. Can't figure out why it won't work
    By array in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2004, 12:29 PM

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