Paycheck calulator

Hello All,

I'm trying to build a paycheck calulator that gives me my net pay after user's input their hours worked and rate of pay. however, the system is not working and telling me the netpay is $0 which is wrong

my code is

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
using namespace std;

int main() {
	double hoursworked;
	double ratepaid;
	double paycheck{};
	string custname;

	double totalSStax, totalMedCare, totalStateTax, totalDeduct, totalPay;

	double socsectax = 0.0625;
	double medicaretax = 0.0145;
	double statetax = 0.0425;


	totalSStax = paycheck * socsectax;

	totalMedCare = paycheck * medicaretax;

	totalStateTax = paycheck * statetax;


	totalDeduct = totalSStax + totalMedCare + totalStateTax;


	totalPay = paycheck - totalDeduct;
	cout << "                                   *Hello! Welcome to Charles's paycheck calulator system*" << endl;
	cout << "_____________________________________________________________________________________________________________________" << endl;

	cout << "First, Please tell me your name? " << endl;
	getline(cin, custname);
	cout << "__________________________________________________" << endl;

	cout << "How many hours do you work each week " << custname << "?" << endl;
	cin >> hoursworked;
	cout << "__________________________________________________" << endl;

	cout << endl;
	cout << "So tell me how much you make per hour " << custname << "?" << endl;
	cin >> ratepaid;
	cout << "__________________________________________________" << endl;

	cout << endl;

	paycheck = hoursworked * ratepaid;

	cout << custname << " Your paycheck is: " << "$" << paycheck << endl;
	cout << "__________________________________________________" << endl;

	cout << "Your net pay after taxes is " << "$" << totalPay << endl;

	cout << "                                  Thank you for using. Have a great day!" << endl;



	return 0;

}
Last edited on
please code tag <> in the mini bar side editor.
you appear to do all your computations BEFORE you read in the info to set paycheck. You need to reorder so that you get their info, figure out their check, and THEN find the deductions.
Hello cblack618,

As jonnin pointed out.


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



What you have works, I just rearranged some lines and made some changes that should help you out in the future.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <limits>  // <--- Added.
#include <string>

//using namespace std;  // <--- Best not to use.
// A recent post that is worth reading. http://www.cplusplus.com/forum/beginner/258335/

int main()
{
	constexpr double SOCSECTAX{0.0625};
	constexpr double MEDICARETAX{ 0.0145 };
	constexpr double STATAETAX{ 0.0425 };
	constexpr size_t WIDTH{ 57 };

	double hoursworked{};
	double ratepaid{};
	double paycheck{}; // <--- Only one that was initialized.
	double totalSStax{}, totalMedCare{}, totalStateTax{}, totalDeduct{}, totalPay{};
	std::string custname;

	std::cout << "\n *Hello! Welcome to Charles's paycheck calulator system*" << std::endl;
	std::cout << std::string(WIDTH,'_') << '\n' << std::endl;

	std::cout << "First, Please tell me your name? ";
	std::getline(std::cin, custname);
	std::cout << std::string(WIDTH, '_') << '\n' << std::endl;

	std::cout << "How many hours do you work each week " << custname << "? ";
	std::cin >> hoursworked;
	std::cout << std::string(WIDTH, '_') << '\n' << std::endl;

	//cout << endl;
	std::cout << "So tell me how much you make per hour " << custname << "? ";
	std::cin >> ratepaid;
	std::cout << std::string(WIDTH, '_') << '\n' << std::endl;

	std::cout << std::endl;

	paycheck = hoursworked * ratepaid;

	totalSStax = paycheck * SOCSECTAX;

	totalMedCare = paycheck * MEDICARETAX;

	totalStateTax = paycheck * STATAETAX;

	totalDeduct = totalSStax + totalMedCare + totalStateTax;

	totalPay = paycheck - totalDeduct;

	std::cout << custname << " Your paycheck is: " << "$" << paycheck << std::endl;
	std::cout << std::string(WIDTH, '_') << '\n';

	std::cout << "\nYour net pay after taxes is " << "$" << totalPay << std::endl;

	std::cout << "\n\n Thank you for using. Have a great day!" << std::endl;

	// A fair C++ replacement for "system("pause")". Or a way to pause the program.
	// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue: ";
	std::cin.get();

	return 0;
}


Hope that helps,

Andy
Andy,

Thank you so much for your help and tips
You are welcome.

Andy
Hello cblack618,

For the fun part adjust the program to deal with hours over 40.

Andy
Topic archived. No new replies allowed.