# constants

can someone help me understand constants please. Here is my program i'm writing, but it's not working the deductions right.
char lastName[10];
char firstName[10];
float hoursWorked;
double grossPay =0;
double rate;
const double sTax    = .075;
const double fTax    = .15;
const double miscDed = .20;
double netIncome;
double deduction;

//Calculate pay and deductions
grossPay = hoursWorked * rate;
deduction = (sTax + fTax + miscDed);
netIncome = grossPay * deduction;

thanks,
nationnon

LVL 1
###### Who is Participating?

Commented:
double grossPay =0;
double rate;
const double sTaxPct    = .075;
const double fTaxPct    = .15;
const double miscDedPct = .20;
double sTaxAmt ;
double fTaxAmt;
double miscDedAmt;

double netIncome;
double deduction;

//Calculate pay and deductions
grossPay = hoursWorked * rate;
sTaxAmt = sTaxPct*grossPay;
fTaxAmt = fTaxPct*grossPay;
miscDedAmt = miscDedPct*grossPay;

deduction = (sTaxAmt + fTaxAmt + miscDedAmt);
netIncome = grossPay - deduction;

netIncome = grossPay * deduction;

was close, but it was calculatign the total deduction amount, not the net amount.  It should have been

netIncome = grossPay * (1-deduction);

but the method I give above is better when you have to start considering rounding to cents.)
0

Commented:
what kind of output are you getting
0

Author Commented:
Enter hours worked: 40
Enter pay rate: 10
r r's gross pay was 400 but after deductions pay is now 170

Press any key to continue

0

Author Commented:
that's not the right deduction
are the constants right?
0

Commented:
nationnon:
your constants are fine.  your code is also fine except the last line. I believe it should read:
netIncome=netIncome - netIncome * deduction.
Give this a try.
0

Commented:
correction: netIncome = grossPay - grossPay * deduction;
0

Commented:
Hi,
I think u need to use the following formula,

deduction = (sTax + fTax + miscDed)*rate * hoursWorked ;
netIncome = grossPay - deduction;

Thats it....

0

Commented:
True, but the other problem is that sTax and fTax are holding the tax _percents_ not the tax themselves.

Use an exampel to help you.  If you are in the 10% bracket (I wish) and you earn \$100 (okay I don't wish) your tax should be \$10 and you net shoudl be \$90.

So

Tax = TaxPercent*Gross;
Net = Gross-Tax;
0

Commented:
kishore joshi:
you just stated my answer in a different form.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.