hello, I am calculating total pay for information stored in structs. total pay is calculated by an adding 10% of base pay for every five (5) hours over forty (40) to base pay. (ie a
person working 50 hours with a total pay of $100 would have ((hours-40)/5)*(base pay*.1) + base pay.
When i run the program I get an undefined number as the output. Am i not using the correct loops to do this calculation?
below is the function i have to calculate the total pay.
The Calc_jd does not look like a member function and num_workers is not a function local name. If that compiles, then you have global variables. Globals are usually a rather restrictive design.
Should the line 8 store its result to somewhere? (That does not cause the observed error.)
yes line 8 should store result to the element array of the total pay only if hours work is greater than 40. Here is the full program that i have completed so far.
Thanks for not telling us what the error is. This is so much more fun when we have to do more of the work.
[/sarcasm]
EDIT: I don't see anything wrong with your if statement, but I do see something wrong with the line following it, line 45. You're attempting to modify the value of ((a[index].hours_worked-40)/5)*(a[index].total_pay*.1) But that makes no sense, because ((a[index].hours_worked-40)/5)*(a[index].total_pay*.1) isn't a variable you can just set the value of.
In technical language, we call ((a[index].hours_worked-40)/5)*(a[index].total_pay*.1) an rvalue, because it can only be used on the right-hand side of an assignment expression.
What is it that you're actually trying to change the value of?
When hours worked is greater than 40 I would like to change the value of the elements in total pay that make the condition true. Would a do while loop be more efficient for this?
To paraphrase what MikeyBoy said regarding line 45, you can't do calculation on the left side of an assignment statement. The calculation belongs on the right hand side. I suspect you simply got the statement backwards.
No. All loops generate pretty much the same code. Use whatever form of a loop suits the problem. i.e. Use a for loop when you want to iterate over a known number of objects. Use a while or do/while to loop while a condition is true. Worrying about the efficiency of one type of loop over another is generally a waste of time.
ok i made the correction by putting a[index].total_pay = (a[index].hours_worked-40)/5)*(a[index].total_pay*.1
but i still end with the output of 4.94066e-324.