inherit
143665
wildgoosespeeder wildgoosespeeder wildgoosespeeder
0
Jun 14, 2018 5:59:55 GMT -8
wildgoosespeeder
ProBoards V5 be trippin'. I'm disoriented. :P
4,393
August 2009
wildgoosespeeder
|
Post by wildgoosespeeder on Nov 14, 2012 11:48:40 GMT -8
For a class, I am supposed to compute federal tax based on this information: If gross pay is: | Federal tax is: | Less than $100 | $0.00 | $100 or more but less than $500 | 15% of the gross over $100. | $500 or more but less than $1,000 | $60 + 28% of the gross over $500. | $1,000 or more | $200 + 31% of the gross over $1,000. |
The code I came up with: void Employee::ComputeFederalTax() { float multiplier = .0f; FederalTax = .0f; if(100.0f <= GrossPay && GrossPay < 500.0f) { multiplier = .15f; } else if(500.0f <= GrossPay && GrossPay < 1000.0f) { multiplier = .28f; FederalTax = 60.0f; } else if(1000.0f <= GrossPay) { multiplier = .31f; FederalTax = 200.0f; } FederalTax += (multiplier * GrossPay); } Assume everything is declared and initialized properly.Output (click to enlarge): Instructor: | Mine: | | |
For John Morgan, the computed Gross Pay is $2,000. The instructor output is different than my output. What am I doing wrong? If I don't get this fixed within this discussion before November 15 at 1:00AM CST, I'll turn in whatever I got because I got less than 12 hours, starting now, to figure this out.
|
|
inherit
143665
wildgoosespeeder wildgoosespeeder wildgoosespeeder
0
Jun 14, 2018 5:59:55 GMT -8
wildgoosespeeder
ProBoards V5 be trippin'. I'm disoriented. :P
4,393
August 2009
wildgoosespeeder
|
Post by wildgoosespeeder on Nov 14, 2012 13:04:25 GMT -8
OK, figured it out. I needed an offset of some kind. Declared one to be 0 and then updated the value within each "if" statement to be 100, 500, or 1000 if one of the "if" statements are tripped. Then updated the last computation. Updated: void Employee::ComputeFederalTax() { float multiplier = .0f; float offset = .0f; FederalTax = .0f; if(100.0f <= GrossPay && GrossPay < 500.0f) { multiplier = .15f; offset = 100.0f; } else if(500.0f <= GrossPay && GrossPay < 1000.0f) { multiplier = .28f; offset = 500.0f; FederalTax = 60.0f; } else if(1000.0f <= GrossPay) { multiplier = .31f; offset = 1000.0f; FederalTax = 200.0f; } FederalTax += (multiplier * (GrossPay - offset)); }
Lock it please!
|
|