I'm creating a payroll program and one of the things I'm trying to do is determine whether or not the employee in question has worked any overtime hours, and if so, calculate how many they worked. My function on line 56 attempts to do this. The function calcOvrTmeHrs takes a Payroll object as a parameter, and starts by trying to determine if the employee has worked over 40 hours. Thats where I'm getting the error that says: Error": expected a'('
Copy and paste the exact error message you are getting and please indicate which line it is referring to.
Also, you seem to have some misconceptions about classes - have you heard of the this pointer? You seem to have designed the functions to take their own instance as parameters. Also, the ones that deal with multiple instances should not exist (or should not be inside the class at all).
Thats one of the things that was confusing me, I can build it fine without any errors, but on line 60, there is a red line under empObj that reads Error: expected a '('
I'm not entirely sure what you mean by
You seem to have designed the functions to take their own instance as parameters.
Also, this is only my header file, the cpp file I haven't created yet where I would actually go and create the instances that are going to be used in the functions.
The reason you can build it fine without any errors is because the header is not being included by any source files yet so it is not even being compiled at all. Your red squiggly line is right - the conditions for if statements have to have round parens () around them. This isn't python ;)
As for my confusing statement, would you please explain to me why on lines 56, 71, and 76 you have that parameter?
Any why are the functions on lines 81-94 even in the class at all? Why do they even exist if they only complicate a simple task?
I can't believe I would forget something so simple like parentheses around conditions in an if statement. Thanks for helping me resolve that.
For lines 56, 71, 76, I was first going to create some Payroll objects in my cpp file and give them each some values, then I would pass the object to the desired function that I wanted to use. That's the gist of what I was attempting to do with those lines you mentioned.
I've been teaching myself C++ for about a month and a half now and I haven't really covered classes/objects extensively yet, so I must not be understanding something that I thought I did, regarding classes and passing objects as parameters.
As far as lines 81-94, now that I think about it, I probably could accomplish those same tasks by using my functions I already have. I probably don't even need those functions on lines 81-94. I'm not sure if that's what you were getting at when you mentioned those lines in your post, but that's just what came to mind when looking at the program again.
So I made several corrections and finally got my program to work the way it should and give me the correct output. One question I had was, instead of having all the input and output done in main, shouldn't I be able to have functions that do that? Where I would simply have to call the getinput function from main and it would gather user input and store it in the array of objects. Then do the same thing for output. I tried having a member function in my Payroll class that gets user input, but I couldn't figure out how to call it properly, as well as get the input stored in the array.
You can have function for input and output if you want, but it is bad practice to do that. Instead, it is more proper to overload the >> and << operators instead.