I am working on an overtime pay project, and I thought I was doing well. Unfortunately, my program is not displaying what it should. It's not completed yet, but it is a problem with having more than one object from a single class.
In my book, it says that you have to list a second object's attributes in terms of the first. I am not sure how to do that when the program prompts the user to enter in all the values.
OK, I have a class called CEmployee that looks like this:
CEmployee Employ1;
CEmployee Employ2;
CEmployee Employ3;
cout << "\n\nEnter the first employee's name = ";
cin >> Employ1.EmployeeName;
cout << "Enter the hours worked = ";
cin >> Employ1.m_hours ;
cout << "Enter his or her hourly wage = ";
cin >> Employ1.m_wage ;
cout << "\n\nEnter the second employee's name = ";
cin >> Employ2.EmployeeName;
cout << "Enter the hours worked = ";
cin >> Employ2.m_hours ;
cout << "Enter his or her hourly wage = ";
cin >> Employ2.m_wage ;
cout << "\n\nEnter the third employee's name = ";
cin >> Employ3.EmployeeName;
cout << "Enter the hours worked = ";
cin >> Employ3.m_hours ;
cout << "Enter his or her hourly wage = ";
cin >> Employ3.m_wage ;
Does this look correct so far or am I way off base here?
Welcome to the Employee Pay Center
Enter the employee name = John
Enter the hours worked = 44
Enter his or her hourly wage = 3.33
Enter the employee name = Mary
Enter the hours worked = 33
Enter his or her hourly wage = 2.22
Enter the employee name = Mark
Enter the hours worked = 29
Enter his or her hourly wage = 2.22
Employee Name ............. = John
Base Pay .................. = 133.20
Hours in Overtime ......... = 4
Overtime Pay Amount........ = 19.98
Total Pay ................. = 153.18
Employee Name ............. = Mary
Base Pay .................. = 73.26
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 73.26
Employee Name ............. = Mark
Base Pay .................. = 64.38
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 64.38
but the numbers for the base pay (only for the 2nd and third Employ) are being displayed like this:
Welcome to the Employee Pay Center
Enter the employee name = John
Enter the hours worked = 44
Enter his or her hourly wage = 3.33
Enter the employee name = Mary
Enter the hours worked = 33
Enter his or her hourly wage = 2.22
Enter the employee name = Mark
Enter the hours worked = 29
Enter his or her hourly wage = 2.22
Employee Name ............. = John
Base Pay .................. = 133.20
Hours in Overtime ......... = 4
Overtime Pay Amount........ = 19.98
Total Pay ................. = 153.18
Employee Name ............. = Mary
Base Pay .................. = 4.99142e+034
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 73.26
Employee Name ............. = Mark
Base Pay .................. = 1.7402e-039
Hours in Overtime ......... = 0
Overtime Pay Amount........ = 0.00
Total Pay ................. = 64.38
I know it's a cout flag, but don't remember and don't have my compiler handy. They are displaying that way because there are too many digits so it's showing sci...
lol,,, actually reading the results... are you dividing by a number approaching zero or something? the ones that have that output have zeros under them... make sure of your math also, just to be safe.. something to do with overtime, but don't see the rest of the code
//Initialize overtime variables
m_overtime_hours=0;
m_overtime_wage=0;
m_overtime_pay=0;
if (m_hours > 40)
{
// Calculate base pay by multiplying the wage by 40
m_basepay = 40*m_wage;
// Calculate overtime hours by subtracting 40 from the hours worked
m_overtime_hours = (m_hours-40);
// Calculate overtime wage by multiplying the wage by 1.5
m_overtime_wage = m_wage*1.5;
// Calculate the overtime pay by multiplying the overtime wage by the overtime hours
m_overtime_pay = m_overtime_hours*m_overtime_wage;
// Calculate this employee's total salary by adding the base pay and the overtime pay
m_salary = m_overtime_pay + m_basepay;
DisplayEmployInformation();
} // End if (m_hours > 40)
else
{
// Calculate the salary by multiplying the hours by the wage
m_salary = m_hours*m_wage;
DisplayEmployInformation();
} // End of the else
In the else portion, the base pay isn't set...only the salary. I have to add this:
you caught me as I was signing out... do you mean how do you make the function?
if you don't want to allow the function to change something it could be (void can be changed if you want to return something also...). Sending as a reference to avoid creating another var, but if you need a copy that doesn't change the send var, then you can remove both the "const" and "&"..
1 2 3
void nameOfFunction( const CEmployee & ce ) {
// do something with ce
}
and if you want to make changes
1 2 3
void nameOfFunction( CEmployee & ce ) {
// do something with ce
}
In general terms, it depends what you're using as your console. In specific terms, if you're using the standard Windows console, or one of the standard *nix consoles, then yes.
I'm guessing you're using windows; as I recall, up under one of the menu options is something like "Mark". If you select that, you can then highlight all the text, and if you press Enter, it'll be copied to the clipboard.
However, for bonus points, put all your output to a log file as well as to the stdout. :)