/**************************************************************
This program asks the user for employee type and either annual
salary or hourly wage along with street address, city, state,
zip code, and then calculates all taxes and displays the data.
***************************************************************/
#include <iostream>
#include <string>
using namespace std;
void getInput(string& city, string& state, string& address, int& zip, double& health_ins);
void grosspaycalc(char payperiod, double salary, double rateofpay, double hoursworked, double& regularpay, double& overtimepay, double& grosspay);
void deductions(double& medicarededuct, double& ficadeduct, double& healthdeduct, double& health_ins, double grosspay, double& netpay);
void displayOutput(double hoursworked, double grosspay, double ficadeduct, double healthdeduct, double medicarededuct, double regularpay, double overtimepay,double netpay, char payperiod);
void employeeType(char& employee, double& hoursworked, double& rateofpay);
void managementInput(double& salary, char& payperiod);
void hourlyInput(double& hoursworked, double& rateofpay);
int main()
{
char employee = 'j';
char payperiod = 'n';
char quitoption = 'y';
string address = "string";
string city = "string";
string state = "string";
int zip = 0;
double hoursworked = 0.00;
double salary = 0.00;
double grosspay = 0.00;
double netpay = 0.00;
double ficadeduct = 0.00;
double healthdeduct = 0.00;
double medicarededuct = 0.00;
double rateofpay = 0.00;
double overtimepay = 0.00;
double regularpay = 0.00;
double health_ins = 0.00;
getInput(city, state, address, zip, health_ins);
employeeType(employee, hoursworked, rateofpay);
grosspaycalc(payperiod, salary, rateofpay, hoursworked, regularpay, overtimepay, grosspay);
deductions(medicarededuct, ficadeduct, healthdeduct, health_ins, grosspay, netpay);
displayOutput(hoursworked, grosspay, ficadeduct, healthdeduct, medicarededuct, regularpay, overtimepay, netpay, payperiod);
return(0);
}
void getInput(string& city, string& state, string& address, int& zip, double& health_ins)
{
cout << "Please enter your Street Address:" << endl;
cin >> address;
cout << "Please enter your city:" << endl;
cin >> city;
cout << "Please enter your state:" << endl;
cin >> state;
cout << "Please enter your zip code:" << endl;
cin >> zip;
cout << "Please enter health insurance percentage as a decimal:" << endl;
cin >> health_ins;
return;
}
void employeeType(char& employee, double& hoursworked, double& rateofpay)
{
char payperiod;
char repeat;
double salary = 0.00;
do
{
cout << "Enter type of employe: Management (M or m) or Hourly (H or h):\n";
cin >> employee;
if(employee == 'M' || employee == 'm')
{
repeat = 'n';
managementInput(salary, payperiod);
}
else if(employee == 'H' || employee == 'h')
{
repeat = 'n';
hourlyInput(hoursworked, rateofpay);
}
else
{
cout << "Not a valid option please re-enter." << endl;
repeat = 'y';
}
}while(repeat == 'y');
return;
}
void managementInput(double& salary, char& payperiod)
{
char repeat = 'y';
cout << "Enter annual salary\n";
cin >> salary;
do
{
cout << "\nEnter pay period type: Weekly(W or w), Biweekly(B or b), or Monthly(M or m)\n";
cin >> payperiod;
if(payperiod == 'W' || payperiod == 'w' || payperiod == 'B' || payperiod == 'b' || payperiod == 'M' || payperiod == 'm')
repeat = 'n';
}while(repeat == 'y');
return;
}
void hourlyInput(double& hoursworked, double& rateofpay)
{
using namespace std;
cout << "Enter rate of pay:";
cin >> rateofpay;
cout << "\nEnter number of hours worked:";
cin >> hoursworked;
return;
}
void grosspaycalc(char payperiod, double salary, double rateofpay, double hoursworked, double& regularpay, double& overtimepay, double& grosspay)
{
double overtimehours = 0.00;
const double OVERTIME = 1.5;
const int WEEKLY = 52;
const int BIWEEKLY = 26;
const int MONTHLY = 12;
const int NORMWEEK = 40;
if(payperiod == 'n')
{
if(hoursworked <= 40.0 && hoursworked >= 0.0)
{
grosspay = hoursworked * rateofpay;
}
else if(hoursworked > 40.0)
{
regularpay = NORMWEEK * rateofpay;
overtimehours = hoursworked - NORMWEEK;
overtimepay = overtimehours * (rateofpay * OVERTIME);
grosspay = overtimepay + regularpay;
}
}
else
{
switch(payperiod)
{
case 'W':
case 'w':
grosspay = salary / WEEKLY;
break;
case 'B':
case 'b':
grosspay = salary / BIWEEKLY;
break;
case 'M':
case 'm':
grosspay = salary / MONTHLY;
break;
default:
cout << "That is not valid." << endl;
break;
}
}
return;
}
void deductions(double& medicarededuct, double& ficadeduct, double& healthdeduct, double& health_ins, double grosspay, double& netpay)
{
const double FICA = 0.07;
const double MEDICARE = 0.02;
ficadeduct = grosspay * FICA;
healthdeduct = grosspay * health_ins;
medicarededuct = grosspay * MEDICARE;
netpay = grosspay - (ficadeduct + healthdeduct + medicarededuct);
return;
}
void displayOutput(double hoursworked, double grosspay, double ficadeduct, double healthdeduct, double medicarededuct, double regularpay, double overtimepay,double netpay, char payperiod)
{
if(payperiod == 'n')
{
if(hoursworked <= 40.0 && hoursworked >= 0.0)
{
cout << "Gross Pay:" << grosspay;
cout << "\nFICA deductions:" << ficadeduct;
cout << "\nHealth Insurance deductions:" << healthdeduct;
cout << "\nMedicare deductions:" << medicarededuct;
cout << "\nNet Pay:" << netpay;
}
else if(hoursworked > 40.0)
{
cout << "Regular Pay:" << regularpay;
cout << "\nOvertime Pay;" << overtimepay;
cout << "\nGross Pay:" << grosspay;
cout << "\nFICA deductions:" << ficadeduct;
cout << "\nHealth Insurance deductions:" << healthdeduct;
cout << "\nMedicare deductions:" << medicarededuct;
cout << "\nNet Pay:" << netpay;
}
}
else
{
cout << "Gross Pay:" << grosspay;
cout << "\nFICA deductions:" << ficadeduct;
cout << "\nHealth Insurance deductions:" << healthdeduct;
cout << "\nMedicare deductions:" << medicarededuct;
cout << "\nNet Pay:" << netpay;
}
return;
}
Program logic errorThe program compiles but does not give the correct results
Page 1 of 1
2 Replies - 720 Views - Last Post: 13 November 2009 - 08:55 AM
#1
Program logic error
Posted 12 November 2009 - 07:02 PM
I have compiled this program with no errors but cannot get the correct results. It may be a logic error but I can't figure it out. It was for a class but I have already submitted it. Now it is just a problem I need to solve.
Replies To: Program logic error
#2
Re: Program logic error
Posted 12 November 2009 - 07:23 PM
Quote
It may be a logic error but I can't figure it out.
What information have you gathered that would help in finding out the bug?
#3
Re: Program logic error
Posted 13 November 2009 - 08:55 AM
Write down what results you were expecting and what you have received instead, this way we can help you
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|