What Am I Doing Wrong?

I am writing a simple program for my C++ homework. I need to create a console app that calculates Gross Pay and Net Pay based on Hours Worked and Rate of Pay, with a tax rate of 28%.

To test it, I found an equation that I know the answers to: 40 hours @ $16/h with 7.650% tax.
It's supposed to come out at $640 Gross, and $48.96 in tax, and a Net total of $591.04. However, it keeps coming up with $45.90. I can't go to the next step if this is incorrect.
Does anyone know what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int hrsWork;
int rtPay;
int grossIncome;
double decimalGross;
double tax;
double netIncome;
	cout << "Enter Hours Worked: " << endl;
	cin >> hrsWork;
	cout << "Enter Rate of Pay: " << endl;
	cin >> rtPay;
	    cout << fixed << setprecision(2);
		    grossIncome = hrsWork*rtPay;
		    decimalGross = grossIncome/100;
		    tax = decimalGross*7.650;
                    netIncome = tax-grossIncome;
	cout << "Your Gross Income is $" << grossIncome << endl;
	cout << "Your Tax is $" << tax << endl;
        cout << "Your Net Income is $" << netIncome << endl;

return 0;

}
Last edited on
1
2
3
4
5
// decimalGross = grossIncome/100;
decimalGross = grossIncome/100.0 ; // avoid integer division

// netIncome = tax-grossIncome;
netIncome = grossIncome - tax ; // correct typo 
Yes, that did! How does the extra decimal point change it like that?
Because without a '.0' decimal gross will be integer and will not have the fraction part. :)
CobaltThunder,

unless
1
2
3
int hrsWork;
int rtPay;
int grossIncome;

need to be ints change them to doubles. That worked for me.

Also netIncome = tax-grossIncome; should be netIncome = grossIncome - tax otherwise you will end up with a negative number.

For what it is worth,

Andy
Topic archived. No new replies allowed.