So I am writing a Payroll Program. What I am confused about is, I am using a function to do a math of an employees payment that he has incurred. I included my code below. The portion I am talking about is first initiated in the main() function of my program. I initialize the variable "payment" and send it to the function "ratecalc" to be worked out and returned. But I run into a problem when referencing the variable again in the program, the variable gets reset to 0.00 some how and I have been unable to figure it out. Any advise is helpful. Thanks -DL
Here is data input for anyone who wants to try it.
1 2 3 4 5 6 7
Tom Anderson 7.52 45 N
Bob Conerley 17.50 40 S
John Potter 9.30 35 S
Terrance Appleby 31.00 42 F
Joseph Rinker 17.00 35 F
Todd Russell 5.00 30 S
Bill Ryan 18.25 45 N
In line 87, you initialize payment: double payment = ratecalc(rate, hours);
However, before that initialization, you initialize it to 0.0 at line 49: double payment = 0;
Line 49 should read: double payment = 0.0;
as that is what the compiler is expecting. Also, assume that the computer is dumber than you are. If you can't tell the difference between what values a local variable should actually hold, the computer definitely won't. Making the variable names different, maybe renaming the one inside "ratecalc()" function as 'wages' or 'earnings' or something else along those lines, would solve your problem. See if that helps.