Applying overtime in a calcPay program

I set up my program to run based off the employee putting in what the time worked for each week for 5 weeks but I'm having trouble figuring out how to calculate the overtime on the hours worked as a whole (anything over 200 hours) but now realize that's not right, it should be on each week? Either way, I can't get the overtime rate to work.

Any help would be greatly appreciated.

This is what I have so far.

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

using namespace std;

void instructions(string &name, float &rate, float &sum);
string getName();
float getRate();
float getHours();
float calcPay(float rate, float sum);
float calcGross(float pay);
float calcAmount(float gross);
float calcNet(float gross, float with);
void output(string name, float rate, float sum, float with, float gross, float net, float\
pay);

int main()
{
string name, done;
int counter;
float rate, sum, gross, with, pay, net;
instructions(name, rate, sum);
pay = calcPay(rate, sum);
gross = calcGross(pay);
with = calcAmount(gross);
net = calcNet(gross, with);
output(name, rate, sum, with, gross, net, pay);
return 0;
}

void instructions(string &name, float &rate, float &sum)
{
name = getName();
rate = getRate();
sum = getHours();
}

string getName()
{
string name, done;
cout<<"Enter the name of the employee: "<<" ";
cin>>name;
return name;
}

float getRate()
{
float rate;
cout<<"Enter the hourly pay rate: "<<" ";
cin>>rate;
return rate;
}

float getHours()
{
int counter;
float hours, sum=0;
for (counter=1; counter <=5; counter++)
{
cout<<"Enter the number of hours worked for Week "<<counter<<":"<<" ";
cin>> hours;
if(hours <=200)
cout<<rate * hours <<endl;
if ((hours -200) >=200
cout<< "overtime Pay:" << (hours -200)*(rate*1.5))<<;
sum += hours;
}
return sum;
}

float calcPay(float rate, float sum)
{
float pay;
pay = rate * sum;
return pay;
}

float calcGross (float pay)
{
float gross;
gross = (pay * 1);
return gross;
}

float calcAmount(float gross)
{
float with;
if (gross > 1450)
with = (gross *.21);
else
with = (gross *.10);
return with;
}

float calcNet(float gross, float with)
{
float net;
net = gross - with;
return net;
}

void output(string name, float rate, float sum, float with, float gross, float net, float\
pay)
{
gross = calcGross(pay);
with = calcAmount(gross);
net = calcNet(gross, with);
cout<<"Payroll"<<'\n';
cout<<"======================================="<<'\n';
cout<<"Employee name: "<<name<<'\n';
cout<<"Gross pay: $ "<<gross<<'\n';
cout<<"Total Withholding: $ "<<with<<'\n';
cout<<"Net pay: $ "<<net<<'\n';
}
Whether you calculate overtime weekly or every 5 weeks will not change the outcome. I'd find it more efficient to do the calculation after you have the data for all 5 weeks, as then you will only need to do a single calculation rather than 5 separate ones. To start, I'd place those calculations in the calcPay() function, rather than the getHours() function. Also, your calculations are incorrect; You don't want to calculate overtime if you work more than 200 hours every week, as there are only 168 hours in a week! The conditions that you are checking for are also incorrect, take a look at those. Remember that in the end, you'll want to calculate the overtime pay and add it to the non-overtime pay. Think about these things, and let me know if you need any help. I have a solution completed, but I'd rather not release it unless you are 100% stuck.
After spending a few hours on this. I thought I figured out how to incorporate the overtime and fixed the bugs along the way but now when I run the program it doesn't calculate the gross pay, withholding or net pay anymore. This is what I did...

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

using namespace std;

void instructions(string &name, float &rate, float &sum);
string getName();
float getRate();
float getHours();
float calcGross(float rate, float sum);
float calcAmount(float gross);
float calcNet(float gross, float with);
void output(string name, float rate, float sum, float with, float gross, float net, float\
pay);

int main()
{
string name, done;
int counter;
float rate, sum, gross, with, pay, net;
instructions(name, rate, sum);
pay = calcGross(rate, sum);
with = calcAmount(gross);
net = calcNet(gross, with);
output(name, rate, sum, with, gross, net, pay);
return 0;
}

void instructions(string &name, float &rate, float &sum)
{
name = getName();
rate = getRate();
sum = getHours();
}

string getName()
{
string name, done;
cout<<"Enter the name of the employee: "<<" ";
cin>>name;
return name;
}

float getRate()
{
float rate;
cout<<"Enter the hourly pay rate: "<<" ";
cin>>rate;
return rate;
}

float getHours()
{
int counter;
float hours, sum=0;
for (counter=1; counter <=5; counter++)
{
cout<<"Enter the number of hours worked for Week "<<counter<<":"<<" ";
cin>> hours;
sum += hours;
}
return sum;
}

float calcGross(float rate, float sum)
{
float gross;
if (sum > 200)
gross = (200*rate)+((sum-200)*(rate*1.5));
else
gross = (sum*rate);
return gross;
}

float calcAmount(float gross)
{
float with;
if (gross > 1450)
with = (gross *.15);
else
with = (gross *.25);
return with;
}

float calcNet(float gross, float with)
{
float net;
net = gross - with;
return net;
}

void output(string name, float rate, float sum, float with, float gross, float net, float\
pay)
{
with = calcAmount(gross);
net = calcNet(gross, with);
cout<<"Payroll"<<'\n';
cout<<"======================================="<<'\n';
cout<<"Employee name: "<<name<<'\n';
cout<<"Gross pay: $ "<<gross<<'\n';
cout<<"Total Withholding: $ "<<with<<'\n';
cout<<"Net pay: $ "<<net<<'\n';
}


Any help would greatly appreciated...did I mention I HATE programming?
Topic archived. No new replies allowed.