How do I get these calculations correct?
Could someone Please help me figure out why my calculations are incorrect. I have been working very hard on this and am really confused. I do not see what I am doing wrong or how to fix it. I do not get any error messages. However, when I run the program, the calculations are all incorrect. Please help me out with this.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
double Gross(double);
char mStatusDetermination();
double FederalTax(char, double);
double StateTax(double);
double LocalTax(double);
double MedInsuranceDeductions(char);
double TakeHomePay(double, double, double);
void DisplayPayrollReport(double, double, double,double, double, double, double);
int main(){
char ans;
char MaritalStatus;
double GrossPay, NetPay;
double HourlyRate;
double federalDeductions, stateDeductions, localDeductions;
double TotalDeductions, ExtraDeductions;
cout << " Welcome To The Payroll Calculation Program. \n";
cout << "--------------------------------------------------------------------------------\n";
cout << endl;
do
{
cout << "The rate per hour is: ";
cin >> HourlyRate;
cout << endl;
GrossPay = Gross(HourlyRate);
MaritalStatus = mStatusDetermination();
federalDeductions = FederalTax(MaritalStatus, GrossPay);
stateDeductions = StateTax(GrossPay);
localDeductions = LocalTax(GrossPay);
TotalDeductions = (federalDeductions + stateDeductions + localDeductions);
ExtraDeductions = MedInsuranceDeductions(MaritalStatus);
NetPay = TakeHomePay(GrossPay,TotalDeductions, ExtraDeductions);
DisplayPayrollReport(GrossPay, HourlyRate, federalDeductions, stateDeductions, localDeductions, ExtraDeductions, NetPay);
cout << "\nWould you like to calculate another?(Y/N)? ";
cin >> ans;
cout << endl;
}
while(ans == 'Y' || ans == 'y');
char letter;
cout<<"Enter a letter to end the program:\n";
cin>>letter;
return 0;
}
/************************************************************************************************************************/
double Gross(double HourlyRate)
{
double TotalHours = 0.0;
double HoursWorked;
double OvertimeHrs = 0.0;
double RegPay;
double OvertimePay, grossPay;
char *day[7]={"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
for(int i=0; i<7; i++)
{
cout << "Hours worked on " << day[i] <<": ";
cin >> HoursWorked;
HoursWorked += HoursWorked;
}
cout << endl;
if(HoursWorked < 40)
{
RegPay = HourlyRate * HoursWorked;
}
TotalHours = TotalHours + HoursWorked;
if(TotalHours > 40)
{
OvertimePay = OvertimeHrs * RegPay * 1.5;
grossPay = OvertimePay * RegPay;
}
return (RegPay + OvertimePay);
}
/************************************************************************************************************************/
char mStatusDetermination()
{
char mStatus;
int count = 0;
do
{
cout << "Is Marital Status Married or Single?\n";
cout << "(M=married/S=single):\t";
cin >> mStatus;
cout << endl << endl;
if(mStatus == 'M' || mStatus == 'm' || mStatus == 'S' || mStatus == 's')
count++;
}
while(count < 1);
return mStatus;
}
/************************************************************************************************************************/
double FederalTax(char MaritalStatus, double GrossPay)
{
const double MarriedFedTax =.15;
const double SingleFedTax =.20;
if(MaritalStatus == 'M' || MaritalStatus == 'm')
{
return (GrossPay * MarriedFedTax);
}
else
{
return (GrossPay * SingleFedTax);
}
}
/************************************************************************************************************************/
double StateTax(double GrossPay)
{
const double StateTaxRate = .04;
return (GrossPay * StateTaxRate);
}
/************************************************************************************************************************/
double LocalTax(double GrossPay)
{
const double LocalTaxRate = .02;
return (GrossPay * LocalTaxRate);
}
/************************************************************************************************************************/
double MedInsuranceDeductions(char MaritalStatus)
{
const double MarriedDeductionRate = 18.00;
const double SingleDeductionRate = 10.00;
if(MaritalStatus == 'M' || MaritalStatus == 'm')
{
return MarriedDeductionRate;
}
else
{
return SingleDeductionRate;
}
}
/************************************************************************************************************************/
double TakeHomePay(double GrossPay, double TotalDeductions, double ExtraDeductions)
{
return (GrossPay - TotalDeductions - ExtraDeductions);
}
/************************************************************************************************************************/
void DisplayPayrollReport(double GrossPay, double HourlyRate, double federalDeductions, double stateDeductions,
double localDeductions, double ExtraDeductions, double NetPay)
{
cout<<" Employee Earnings are:\n"
<<"----------------------------------------\n"
<<setw(15)<<"Gross Pay"<<setw(9)<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint)<<GrossPay<<"\n"
<<setw(15)<<"Pay Rate"<<setw(9)<<HourlyRate<<"\n\n\n\n"
<<" Deductions for the WorkWeek are:\n"
<<"------------------------------------------\n"
<<setw(15)<<"Federal Taxes"<<setw(9)<<federalDeductions<<"\n"
<<setw(15)<<"State Taxes"<<setw(9)<<stateDeductions<<"\n"
<<setw(15)<<"Local Taxes"<<setw(9)<<localDeductions<<"\n"
<<setw(15)<<"Insurance"<<setw(9)<<ExtraDeductions<<"\n\n\n\n"
<<setw(15)<<"Net Pay"<<setw(9)<<NetPay<<"\n";
}
Where are my error that's causing incorrect output?
7Stud, Are you here to insult people? My intentions in coming to this message board are not to be attacked, nor is it to be irritating to you or anyone else. I am far from Lazy. I am new to programming, period. Don't discourage people from attempting to get help by trying to be insulting. If you feel that someone is irritating with their post then don't reply, better yet, don't read it! Bottom Line!
Thank you CheesyMoo and gamer4life687 for your tactful responses!
Anyways, to anyone out there who is willing to help me and not try to attack me for trying to get help from others who are more knowledgeable in this field, your feedback will be appreciated.
I have worked on my code and made some changes to try to get my code to work properly. I have been unable to get my program to caculate the employees total pay including their overtime pay. It seems during runtime that my program will calculate the RegularPay but anything over the 40 hours is not calculated properly. Here is the portion of my code where I think the problem is but cant seem to figure it out.
Code:
double Gross(double HourlyPayRate)
{
double TotalHours;
double RegHours;
const int FULL_TIME_HOURS = 40;
double OvertimeHrs = 0.0;
double RegPay;
double OvertimePay;
char *day[7]={"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
for(int i=0; i<7; i++)
{
cout << "Hours worked on " << day[i] <<": ";
cin >> TotalHours;
TotalHours += TotalHours;
}
cout << endl;
if(TotalHours > FULL_TIME_HOURS)
{
OvertimeHrs = TotalHours - FULL_TIME_HOURS;
}
else
{
RegHours = FULL_TIME_HOURS;
}
RegPay = RegHours * HourlyPayRate;
OvertimePay = OvertimeHrs * RegPay * 1.5;
return (RegPay + OvertimePay);
}
I look forward to hearing from those who are really on this board to help.