Reputation: 140
Alright So I finished my program that is basically just calculating up hours worked for 3 employees, nothing too complicated. However, now that I am finished I get two error messages. The first says:
expression must be a modifiable lvalue.
This refers to the use of x.hours
under the Addsomethingup
function. The second error message says:
'=': left operand must be l-value.
This also says that it has something to do with that iTotal_hours
line under the Addsomethingup
function. I am not too familiar with Classes using C++ so if anyone can offer some advice I would really appreciate it.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class EmployeeClass {
public:
string EmployeeName;
int hours;
float wage;
float basepay;
float salary;
int overtime_hours;
float overtime_pay;
float overtime_extra;
float iTotal_salaries;
float iIndividualSalary;
int iTotal_hours;
int iTotal_OvertimeHours;
void ImplementCalculations() {
overtime_hours = 0;
overtime_pay = 0;
overtime_extra = 0;
if (hours > 40) {
overtime_hours = hours - 40;
}
else {
overtime_hours = 0;
}
basepay = 40 * wage;
overtime_pay = wage * 1.5;
overtime_extra = overtime_pay * overtime_hours;
salary = overtime_extra + basepay;
}
void DisplayEmployInformation(void) {
cout << "Employee Name ............. = " << EmployeeName << endl <<
"Base Pay .................. = " << basepay << endl <<
"Hours in Overtime ......... = " << overtime_hours << endl <<
"Overtime Pay Amount........ = " << overtime_pay << endl <<
"Total Pay ................. = " << salary << endl;
}
void Addsomethingup(EmployeeClass x, EmployeeClass y, EmployeeClass z) {
iTotal_salaries = 0;
iTotal_hours = 0;
iTotal_OvertimeHours = 0;
iTotal_salaries = x.wage + y.wage + z.wage;
iTotal_hours = x.hours + y.hours = z.hours;
iTotal_OvertimeHours = x.overtime_hours + y.overtime_hours + z.overtime_hours;
cout << " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%% Total Employee Salaries ..... = " << iTotal_salaries << endl <<
"%%%% Total Employee Hours ........ = " << iTotal_hours << endl <<
"%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours << endl <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" <<
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
}
};
int main()
{
system("cls");
cout << "\nWelcome to the Employee Pay Center\n\n";
EmployeeClass firstEmployee;
EmployeeClass secondEmployee;
EmployeeClass thirdEmployee;
EmployeeClass totalEmployee;
cout << "Please enter the first Employees name: \n"; //First employees input
cin >> firstEmployee.EmployeeName;
cout << "Please enter " << firstEmployee.EmployeeName << "'s hours worked: \n";
cin >> firstEmployee.hours;
cout << "Please enter " << firstEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> firstEmployee.wage;
cout << "Please enter the second Employees name: \n"; //Second emlpoyee input
cin >> secondEmployee.EmployeeName;
cout << "Please enter " << secondEmployee.EmployeeName << "'s hours worked: \n";
cin >> secondEmployee.hours;
cout << "Please enter " << secondEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> secondEmployee.wage;
cout << "Please enter the third Employees name: \n"; //Third employees input
cin >> thirdEmployee.EmployeeName;
cout << "Please enter " << thirdEmployee.EmployeeName << "'s hours worked: \n";
cin >> thirdEmployee.hours;
cout << "Please enter " << thirdEmployee.EmployeeName << "'s hourly wage; \n\n";
cin >> thirdEmployee.wage;
firstEmployee.ImplementCalculations();
secondEmployee.ImplementCalculations();
thirdEmployee.ImplementCalculations();
totalEmployee.Addsomethingup(firstEmployee, secondEmployee, thirdEmployee);
}
Upvotes: 0
Views: 29
Reputation: 180945
Your issue is with
iTotal_hours = x.hours + y.hours = z.hours;
operator precendece dictates that x.hours + y.hours
happens before y.hours = z.hours
so what is actually going on is
iTotal_hours = (x.hours + y.hours) = z.hours;
Which will not work as (x.hours + y.hours)
creates a temporary object that cannot be assigned to.
I think what you meant to have was a +
and not an =
which would make it
iTotal_hours = x.hours + y.hours + z.hours;
which is consistent with what you did for iTotal_salaries
and iTotal_OvertimeHours
Upvotes: 4