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;
}
Also, to output decimal places, use a floating-point type (double or float) instead of an integer.