Need help with Tax project

c++ federal income tax must be withheld from the employee's gross pay. for this project, federal income tax is 10% of gross pay for the first $1000, 15% on the next $15000 and 25% on amounts above $2500, So it should calculate like gross pay is $4000.00 then 10% of the first 1000 = 100, then 15% of the next $1500 = $225 and then 25% on the any amount left over $2,500 in this case would be $1500 * 25% = 375 So total's for all three brackets are $700.

I'm trying to use if statemetns but i'm having trouble storing each amount in a particular variable and not having them over lap - and then add them up at the end to get my total?


Trying to do something like this

if (fedTotalPay>0 && fedTotalPay <=1000)
fedtax =.10 * fedTotalPay;

if (fedTotalPay >1000)
(fedtax1 = (fedTotalPay -1000)) *.10;


if (fedTotalPay >1000 && fedTotalPay <2500)
(fedtax2 = (fedTotalPay -1500)) *.15;
if (fedTotalPay >2500)
(fedtax3 = (fedTotalPay -2500)) *.25;

totalfedtax = fedtax+fedtax1+fedtax2+fedtax3;

1
2
3
4
5
6
7
8
9
10
11
12
13
if (fedTotalPay>0 && fedTotalPay <=1000)//fedTotalPay >0 but not <=1000 false
fedtax =.10 * fedTotalPay;

if (fedTotalPay >1000) //it is >1000 true
(fedtax1 = (fedTotalPay -1000)) *.10; // 300


if (fedTotalPay >1000 && fedTotalPay <2500)//fedTotalPay is >1000 but not <2500 false
(fedtax2 = (fedTotalPay -1500)) *.15;
if (fedTotalPay >2500) //true it is >2500
(fedtax3 = (fedTotalPay -2500)) *.25;// 375

totalfedtax = fedtax+fedtax1+fedtax2+fedtax3;//0+300+0+375=675 


Of course your code is wrong but think about true and false.
Last edited on
You can try something like it:
1
2
3
4
5
6
7
8
9
10
double computeTax(double fedTotalPay ){
if (fedTotalPay < 0) return 0;
if (fedTotalPay < 1000) return 0.1*fedTotalPay;
double total = 100; //1000*0.1
if (fedTotalPay < 2500)
 return total + 0.15*(fedTotalPay - 1000);
total += 0.15*1500;
...
...
}
@tfityo to post

You can try something like it:

will not help ;)
Topic archived. No new replies allowed.