The assignment is to design a program that determines the gross pay for each employee.
Everything seems to work, but when you input more than 40 hours, it doesn't calculate overtime.
Another thing is that, i can't get a message to pop up when someone input an invalid input. I can use an invalid exception, but I want to know why the if statement isn't working.
class OverTime
{
public:
OverTime (float = 0, float = 0);
void sethoursWork(float);
void sethourlyRate(float);
float gethoursWork();
float gethourlyRate();
float getsalary();
private:
float hoursWork;
float hourlyRate;
};
#include "stdafx.h"
#include "OverTime.h"
OverTime::OverTime(float a, float b)
{
hoursWork = a;
hourlyRate = b;
}
void OverTime::sethoursWork(float hW)
{
if (hoursWork > 40)
{
hourlyRate += (hourlyRate /2);
}
else
hoursWork = hW;
}
void OverTime::sethourlyRate(float hR)
{
if (hourlyRate <=0)
{
cout << "Please input greater than zero.";
}
else
hourlyRate = hR;
}
float OverTime::gethoursWork()
{
return hoursWork;
}
float OverTime::gethourlyRate()
{
return hourlyRate;
}
float OverTime::getsalary()
{
return hoursWork * hourlyRate;
}
#include "stdafx.h"
#include "OverTime.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
float hoursWork1;
float hourlyRate1;
char answer;
answer = 'y';
OverTime overTime(0);
do
{
cout << "Enter hours work: ";
cin >> hoursWork1;
cout << "Enter hourly rate: ";
cin >> hourlyRate1;
overTime.sethoursWork(hoursWork1);
overTime.sethourlyRate(hourlyRate1);
cout << "Your Salary is: " << overTime.getsalary() << endl;
cout << "\n";
cout << "Do you want to enter another?";
cin >> answer;
cout << "\n";
} while (answer == 'y');
return 0;
}