I'm working on a project that calculate income for employees by using overloading and also pass by value + pass by reference. I need to use at least one of the functions in program to demonstrate pass-by-value; and at least one of the functions to demonstrate pass-by-reference with reference arguments. Here is what I got so far:
#include <iostream> #include "Grosspay.h" #include "iomanip" using namespace std; double income(double hours, double payrate) { double grosspay = 0; double federaltax = .10; double statetax = .05; double totaltax; double netpay; if (hours <= 40) { grosspay = payrate * hours; }if (hours > 40 && hours <= 50) { grosspay = (payrate * 40) + ((hours - 40) * payrate * 1.5); } if (hours > 50) { grosspay = (payrate * 40) + (10 * payrate * 1.5) + ((hours - 50) * payrate * 2); } cout << "Grosspay weekly is: " << grosspay << endl; federaltax = grosspay * .10; cout << "Federal Tax is: " << federaltax << endl; statetax = grosspay * .05; cout << "State Tax is: " << statetax << endl; totaltax = federaltax + statetax; cout << "Total tax is: " << totaltax << endl; netpay = grosspay - totaltax; return (netpay); } double income(const double &year) { double grosspay; double federaltax = .10; double statetax = .05; double totaltax; double netpay; grosspay = year / 52; cout << "Grosspay weekly is: " << grosspay << endl; federaltax = grosspay * .10; cout << "Federal Tax is: " << federaltax << endl; statetax = grosspay * .05; cout << "State Tax is: " << statetax << endl; totaltax = federaltax + statetax; cout << "Total Tax is: " << totaltax << endl; netpay = grosspay - totaltax; return (netpay); } void Grosspay::determineGrosspay() { cout << "Enter 1 - Calculate payroll for hourly employee" << endl; cout << "Enter 2 - Calculate payroll for salary employee" << endl; cout << "Enter 3 - Exit" << endl; cout << "Federal Tax is 10% of Grosspay" << endl; cout << "State Tax is 5% of Grosspay" << endl; while (choice != 3) { cout << "\nEnter your choice: " << endl; cin >> choice; switch (choice) { case 1: cout << "Enter employee ID: " << endl; cin >> ID; cout << "Enter hours: " << endl; cin >> hours; cout << "Enter payrate: " << endl; cin >> payrate; cout << "Employee ID: " << ID << endl; cout << setprecision(2) << fixed; cout << "The net pay for hourly employee: " << income(hours, payrate) << endl; break; case 2: cout << "Enter employee ID: " << endl; cin >> ID; cout << "Enter salary: " << endl; cin >> year; cout << "Employee ID: " << ID << endl; cout << setprecision(2) << fixed; cout << "The net pay for salaried employee: " << income(year) << endl; break; case 3: cout << "Exited program" << endl; break; default: cout << "Please try again!" << endl; break; } } } One of the genius here told me that I need to put double income(const double &year) for the pass-by-reference. But I'm not really sure what makes the difference! I still have the same output. Can anyone please help me?