简体   繁体   English

我的代码很难

[英]Having a hard time my code

I am taking a C++ class and I have to build a payroll system. 我正在学习C ++课程,我必须建立一个薪资系统。 I am having a hard time trying to figure out what is wrong with my code. 我正在努力弄清楚我的代码有什么问题。 I can get the employees hours to produce but I have an new issue with my code now. 我可以让员工有时间来制作,但现在我的代码出现了新问题。 I thought it was correct, but guess not. 我认为这是正确的,但不要猜。 Now the new problem is that I can get the employees hours to produce but when I do my code wants to multiple my overtime hours times 3 and produce an output of the person who has the overtime hours twice. 现在新的问题是我可以让员工有时间来制作,但是当我做我的代码时想要将我的加班时间加倍3并产生两倍加班时间的人的输出。

#include <iostream>
#include <string>    
#include <iomanip>

using namespace std;

//
//CLASS DECLARATION SECTION
//

class EmployeeClass {
public:
void ImplementCalculations(string EmployeeName, int hours, float wage);
void DisplayEmployInformation(void);
void Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3);
string EmployeeName;
int hours ;
float wage ;
float basepay ;
int overtime_hours ;
float overtime_pay ;
float overtime_extra ;
float iTotal_salaries ;
float iIndividualSalary ;
int iTotal_hours ;
int iTotal_OvertimeHours ;
};

int main()
{   system("cls");

cout << "\nWelcome to Data Max Inc. Employee Pay Center\n\n" ;


EmployeeClass Emp1;
EmployeeClass Emp2;
EmployeeClass Emp3;

cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;

cout << "\n\nEnter the first employee's first name = ";
cin >> Emp1.EmployeeName;

cout << "\n\nEnter the hours worked = ";
cin >> Emp1.hours;

cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp1.wage;

cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;

cout << "\n\nEnter the second employee's first name = ";
cin >> Emp2.EmployeeName;

cout << "\n\nEnter the hours worked = ";
cin >> Emp2.hours;

cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp2.wage;

cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;

cout << "\n\nEnter the third employee's first name = ";
cin >> Emp3.EmployeeName;

cout << "\n\nEnter the hours worked = ";
cin >> Emp3.hours;

cout << "\n\nEnter employee's hourly wage = ";
cin >> Emp3.wage;

cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << endl;

Emp1.ImplementCalculations(Emp1.EmployeeName, Emp1.hours, Emp1.wage);
Emp2.ImplementCalculations(Emp2.EmployeeName, Emp2.hours, Emp2.wage);
Emp3.ImplementCalculations(Emp3.EmployeeName, Emp3.hours, Emp3.wage);



cin.get();
    return 0;    

} //End of Main Function


void EmployeeClass::ImplementCalculations (string employeeFirstName, int hours, float wage){
//Initialize overtime variables
overtime_hours=0;
overtime_pay=0;
overtime_extra=0;

if (hours > 40)
{      


basepay = 40 * wage;
overtime_hours = hours - 40;
overtime_pay = wage * 1.5;
overtime_extra = overtime_hours * overtime_pay;
iIndividualSalary = overtime_extra + basepay;


DisplayEmployInformation();

}   // if (hours > 40)
else
{  
basepay = hours * wage;
iIndividualSalary = basepay;


} // End of the else

DisplayEmployInformation();


} //End of Primary Function

void EmployeeClass::DisplayEmployInformation () {
// This function displays all the employee output information.



cout << "\n\n";
cout << "Employee First Name ............. = " << EmployeeName << endl;
cout << "Base Pay ........................ = " << basepay << endl;
cout << "Hours in Overtime ............... = " << overtime_hours << endl;
cout << "Overtime Pay Amout............... = " << overtime_extra << endl;
cout << "Total Pay ....................... = " << iIndividualSalary << endl;




} // END OF Display Employee Information

void EmployeeClass::Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2,        EmployeeClass Emp3){

iTotal_salaries = 0;
iTotal_hours = 0;
iTotal_OvertimeHours = 0;


iTotal_hours = Emp1.hours + Emp2.hours + Emp3.hours;
iTotal_salaries = iIndividualSalary + iIndividualSalary + iIndividualSalary;
iTotal_OvertimeHours = overtime_hours + overtime_hours + overtime_hours;



cout << "\n\n";
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% Total Employee Salaries ..... = " << iTotal_salaries << endl;
cout << "%%%% Total Employee Hours ........ = " << iTotal_hours << endl;
cout << "%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;

} // End of function

You aren't calling Addsomethingup anywhere. 你不是在任何地方调用Addsomethingup You probably also want this to be a static method. 您可能还希望这是一个static方法。 If you haven't learned what those are yet, don't worry. 如果你还没有学到什么,不要担心。

At the end of your main function, but before cin.get() , try adding: main函数结束时,但在cin.get()之前,请尝试添加:

Emp1.Addsomethingup(Emp1, Emp2, Emp3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM