NetPay program

For some reason or another, I can't get my program to calculate correctly the netpay....

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
30
31
32
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main(){

double hoursWeek; double hourlyPay;
double grossPay=hoursWeek + hourlyPay;
double FWT;
double FICA;
double stateTax;

cout << "Enter your hours worked/week 'hours worked must be 40.0 or less', hourly pay rate, FWT rate, FICA tax rate\n"
<< "and state income tax rate." << endl;
cout << "FICA (Social Security and Medicare) :: FWT (Federal Withholding Tax)" << endl;
cin >> hoursWeek >> hourlyPay >> FWT >> FICA >> stateTax;

double fwtGross = grossPay * FWT;
double ficaGross = grossPay * FICA;
double stateGross = stateTax * grossPay;
double netPay = grossPay - fwtGross - ficaGross - stateGross;

cout << "This is your input: " << endl;
cout << "Hours: " << hoursWeek << "\nHourly pay: " << hourlyPay << "\nFWT: " << FWT << "\nFICA: " << FICA << "\nState Tax: " << stateTax << endl;
cout.precision(2);
cout << "Your net pay is: " << netPay << endl;
cout << fixed;

return 0;
}


someone please explain to me what I'm doing incorrectly. I don't necessarily wish that you hold my hand and rewrite the code for me like a lot of others request, but if you feel like writing the incorrect line, pointing out the incorrect line, or telling me what I'm missing and why, that'd be awesome!

This isn't homework.. I'm just brushing up my basic coding. Been working on the practice solutions that were posted on this website, so I"ll post my issue with the function solution as well in a later post. Thank you.!

--edit: I just got into the habbit of typing up all my includes, for some reason or another, and #include <string> has no play in this whatsoever. no need to point it out :)
Last edited on
You are assigning the sum of two garbage variables to gross pay, then using this value to determine the rest of the calculations.

consider asking for the user to input gross pay, then do the calculations of grossPay=hoursWeek + hourlyPay;
Change double grossPay=hoursWeek + hourlyPay;
to double grossPay;. Then after cin >> hoursWeek >> hourlyPay >> FWT >> FICA >> stateTax; you can do just grossPay=hoursWeek + hourlyPay
With those changed @khal I am not getting an integer followed by a decimal then e^??? anymore, just a whole integer of 2 digits. Is there anything wrong with the calculations?
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
30
31
32
33
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main(){

double hoursWeek; double hourlyPay;
double grossPay;
double FWT;
double FICA;
double stateTax;

cout << "Enter your hours worked/week 'hours worked must be 40.0 or less', hourly pay rate, FWT rate, FICA tax rate\n"
<< "and state income tax rate." << endl;
cout << "FICA (Social Security and Medicare) :: FWT (Federal Withholding Tax)" << endl;
cin >> hoursWeek >> hourlyPay >> FWT >> FICA >> stateTax;
grossPay=hoursWeek + hourlyPay;
double fwtGross = grossPay * FWT;
double ficaGross = grossPay * FICA;
double stateGross = stateTax * grossPay;
double netPay = grossPay - fwtGross - ficaGross - stateGross;

cout << "This is your input: " << endl;
cout << "Hours: " << hoursWeek << "\nHourly pay: " << hourlyPay << "\nFWT: " << FWT << "\nFICA: " << FICA << "\nState Tax: " << stateTax << endl;
cout.precision(2);

cout << "Your net pay is: " << netPay << endl;
cout << fixed;

return 0;
}
you'll want to set precision before you output your data using cout.
I meant to say, my input is only like... 27 bucks if I use 30 for hrs wrked, 10 per hr, .2, .08, .04
Wow... WOWOWOW! So silly I didn't see this..

"grossPay = hoursWeek '+' hoursWorked;"

HA! Thank you all for the help, but I guess even the most brilliant coders forget simple mathematics at times :D
Topic archived. No new replies allowed.