Finding the net pay and adding two decimals

I can't figure out how to provide a net pay after the state tax and I need to add two decimals points to the dollar amounts. Plzz help!

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <stdlib.h>

using namespace std;

void pause()
{
cout << endl << "Press ENTER to exit.";
cin.get();
cin.get();
}

// Hr rate
float GetRate()
{
float hourlyRate;
cout << "Hourly Rate? ";
cin >> hourlyRate;

while (hourlyRate < 5.5 || hourlyRate > 200.00)
{
cout << endl << endl << "Invalid amount of hours! Hourly pay? ";
cin >> hourlyRate;
}
cout << endl;

return hourlyRate;
}

// Hrs worked
float GetHours()
{
float hours;
cout << "Hours worked? ";
cin >> hours;
if (hours < 0.0)
{
cout << "Invalid amount of hours! What are the hours worked?:= ";
cin >> hours;
}
else if (hours > 60.0)
{
cout << "Hours are greater than 60." << endl;
}

return hours;
}

float finalPay(float hours, float hourlyRate)
{
return hours * hourlyRate;
}

void PrintStub(string name, float pay)
{
cout << endl << name << " earned $" << pay << endl;
}

void CalcFICA(float pay)
{
int FICA;
FICA = pay * 0.0765;
cout << "FICA: $" << FICA << endl;
}

void CalcFedTax(float pay)
{
int fedTax;
fedTax = pay * 0.22;
cout << "Federal tax: $" << fedTax << endl;
}

void CalcStateTax(float pay)
{
int stateTax;
stateTax = pay * 0.12;
cout << "State tax: $" << stateTax << endl;
}

int main()
{
// variables
string name;
float hours, hourlyRate, pay, netpay;

cout << "Employee name? ";
cin >> name;
cout << endl;
hourlyRate = GetRate();
hours = GetHours();
pay = finalPay(hours, hourlyRate);
PrintStub(name, pay);
CalcFICA(pay);
CalcFedTax(pay);
CalcStateTax(pay);

pause();
return 0;
}
The net pay is the gross pay - tax.
To output decimal points: http://www.cplusplus.com/reference/iomanip/setprecision/
Also, to output decimal places, use a floating-point type (double or float) instead of an integer.
Here an example:
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// I can't figure out how to provide a net pay after the state tax and I need
// to add two decimals points to the dollar amounts. Plzz help!

#include <iostream>
#include <iomanip>
#include <limits>
#include <string>

void pause();
double getRate();
double getHours();
double finalPay(double hours, double hourly_rate);
void printStub(std::string name, double pay);
double calcFICA(double pay);
double calcFedTax(double pay);
double calcStateTax(double pay);
double calculateNetPay(double pay);

int main()
{
	std::cout << "Employee name? ";
	std::string name;
	std::cin >> name;
	std::cout << std::endl;
	double hourly_rate = getRate();
	double hours = getHours();
	double pay = finalPay(hours, hourly_rate);
	printStub(name, pay);
	std::cout << "Net pay is " << std::fixed << std::setprecision(2)
              << calculateNetPay(pay) << '\n';

	pause();
	return 0;
}

void pause()
{
	std::cout << "\nPress ENTER to continue...\n";
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

// Hr rate
double getRate()
{
	double hourly_rate;
	std::cout << "Hourly Rate? ";
	std::cin >> hourly_rate;

	while (hourly_rate < 5.5 || 200.00 < hourly_rate) {
		std::cout << "\n\nInvalid amount of hours! Hourly pay? ";
		std::cin >> hourly_rate;
	}
	std::cout << std::endl;

	return hourly_rate;
}

// Hrs worked
double getHours()
{
	double hours;
	std::cout << "Hours worked? ";
	std::cin >> hours;
	if (hours < 0.0) {
		std::cout << "Invalid amount of hours! What are the hours worked? ";
		std::cin >> hours;
	} else if (hours > 60.0) {
		std::cout << "Hours are greater than 60." << std::endl;
	}

	return hours;
}

double finalPay(double hours, double hourly_rate)
{ return hours * hourly_rate; }

void printStub(std::string name, double pay)
{
    std::cout << std::endl << name << " earned $" << std::fixed 
              << std::setprecision(2) << pay << std::endl;
}

double calcFICA(double pay)
{
    double fica = pay * 0.0765;
	std::cout << "FICA: $" << std::fixed << std::setprecision(2) 
              << fica << std::endl;
	
	return fica;
}

double calcFedTax(double pay)
{
    double fed_tax = pay * 0.22;
	std::cout << "Federal tax: $" << std::fixed << std::setprecision(2)
              << fed_tax << std::endl;
	
	return fed_tax;
}

double calcStateTax(double pay)
{
    double state_tax = pay * 0.12;
	std::cout << "State tax: $" << std::fixed << std::setprecision(2)
              << state_tax << std::endl;
	
	return state_tax;
}

double calculateNetPay(double pay)
{ return pay - calcFICA(pay) - calcFedTax(pay) - calcStateTax(pay); }


BTW are you sure, if the input hourly rate is out of boundaries, you want your program to warn: "Invalid amount of hours!" ?
Topic archived. No new replies allowed.