I have instantiated an object, bob, and have an array with hours for each day bob has worked. When I try to call bob.biWeeklySalary( hours[] ) it doesn't work. I'm not really sure how to use the array here. The compiler just says that hours is an undeclared identifier.
Your help is very appreciated
#include <iostream>
using std::cout;
using std::endl;
#include "MailCarrier.h"
#include "HireDate.h"
#include "Employee.h"
int main()
{
HireDate bobHire( 4, 8, 2004 );
MailCarrier bob( "Bob", "Johnson", "534-44-9551", bobHire, 19.52 );
bob.getHoursFromUser();
bob.biWeeklySalary( );
bob.Employee::print();
}
#ifndef MAILCARRIER_H
#define MAILCARRIER_H
#include "Employee.h"
#include "HireDate.h"
#include <iostream>
using std::cout;
using std::endl;
class MailCarrier : public Employee
{
public:
MailCarrier();
MailCarrier( const string &, const string &, const string &, const HireDate &, double );
void setPayRate( double );
double getPayRate() const;
void getHoursFromUser();
double biWeeklySalary( double );
private:
double payRate;
double hours[12];
double totalPay;
};
#endif
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "MailCarrier.h"
//Constructor
MailCarrier::MailCarrier()
{
for (int i = 0; i <= 12; i++)
hours[i] = 0;
}
//Constructor
MailCarrier::MailCarrier( const string &first, const string &last, const string &ssn,
const HireDate &, double pay )
//explicitly call base-class constructor
: Employee( first, last, ssn, HireDate( ) )
{
setPayRate( pay ); // validate and store payRate
}
// function to set payRate
void MailCarrier::setPayRate( double pay )
{
payRate = ( pay > 0.0 && pay < 35.0 ) ? pay : 17.17;
}
double MailCarrier::getPayRate() const
{
return payRate;
}
//Function to get hours from user
void MailCarrier::getHoursFromUser()
{
for (int j = 0; j <= 11; j++)
{
cout << "Enter hours for day " << j+1 << ": ";
cin >> hours[ j ];
}
}//End function
//Function to calculate total pay
double MailCarrier::biWeeklySalary( double hours )
{
double pay = 0;
for (int k = 0; k <= 11; k++)
{
if ( hours[ k ] > 10)
pay = ((payRate * 2 * ( hours[ k ] - 10)) + (payRate * 1.5 * 2) + (payRate * 8));
else if ( hours[ k ] > 8)
pay = ((payRate * 1.5 * (*hours[ k ] - 8)) + ( payRate * 8));
else if ( hours[ k ] >= 0)
pay = payRate * 8;
else cout << "Hours entered incorrectly, Please try again!\n" << endl;
totalPay += pay;
}
return totalPay;
}