Overloading Functions
Aug 6, 2013 at 5:11pm UTC
Hi There I have a Code that I wrote to calculate Salaries for weekly and hourly paid employess. The Code works perfectly but the question said I should use a overload function called calcWeeklyPay
Could you give me a indication of What to do ?
This is The Working Code without the Overload Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
using namespace std;
int main()
{
double paidWeekly, paidHourly , hoursWorked, annualSalary, hourlyWage;
int employeeType;
cout << "For Weekly paid employees Enter 0, For Hourly Paid Employees Enter 1: " ;
cin >> employeeType;
if (employeeType==0)
{
cout << "Please Enter Your Annual Salary"
<< " of a Weekly Paid Employee: " ;
cin >> annualSalary;
paidWeekly=annualSalary/52;
cout<<"The Weekly Salary for this employee is: R" <<paidWeekly
<< endl;
}
else
{
cout << "Please Enter Hourly Wage: " ;
cin >> hourlyWage;
cout<< "Enter Hours Worked: " ;
cin >> hoursWorked;
paidHourly=hourlyWage*hoursWorked;
cout<<"The Weekly Salary for this employee is:" <<paidHourly
<< endl;
}
return 0;
}
This is my attempt with the overloading function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
double calcWeeklyPay(double annualSalary);
//Returns the Weekly salary of weekly paid Employees
double calcWeeklyPay(double hourlyWage, double hoursWorked);
//Returns the Weekly salary of Hourly paid Employees
int main()
{
using namespace std;
double annualSalary,hourlyWage,hoursWorked ,paidWeekly,paidHourly
cout << "Please Enter Your Annual Salary"
<< "of a Weekly Paid Employee:" ;
cin >> annualSalary;
paidWeekly = calcWeeklyPay(double annualSalary)
cout<<"The Annual Salary for the weekly paid employee is:" <<paidWeekly
<< endl;
cout << "Please Enter Your hourly wage" ;
cin >> hourlyWage;
cout<< "Enter Hours Worked" ;
cin >> hoursWorked;
paidHourly=calcWeeklyPay(double hourlyWage,double hoursWorked)
cout<<"The Annual Salary for the hourly paid employee is:" <<paidHourly
<< endl;
return 0;
}
double calcWeeklyPay(double annualSalary)
{
double weeklySalary
weeklySalary = annualSalary/52
return weeklySalary;
}
Please Help
Thanks
Aug 6, 2013 at 5:56pm UTC
So define the other function, what part are you having trouble with?
Aug 7, 2013 at 7:24am UTC
Getting The Program To work, If I Run the second code I get 12 Errors
Aug 7, 2013 at 8:08am UTC
on line 19: double annualSalary
is declaring a variable. For passing the variable to the function you need to remove the type (double). The same applies to line 30.
And a ;
is required at the end of line 19/30.
you need to implement the second function double calcWeeklyPay(double hourlyWage, double hoursWorked)
Topic archived. No new replies allowed.