이 코드에서는 사용자에게 이름, 근무 시간 및 시간당 요율을 물어 본 다음 두 가지를 곱해서 월급을 얻습니다. 포인터 함수를 통해이 일을하고 있지만 어떤 이유로 프로그램이 calculate_salary 함수로 이동하면 오류로 끝납니다. 무엇이 잘못되었으며 왜 이런 일이 일어나고 있습니까?클래스의 포인터 함수가 작동하지 않습니다.
#include <iostream>
#include <string>
using namespace std;
class Employee
{
public:
string name;
double salary;
double hours;
double cash_per_hour;
int age;
Employee(){}
double* salary_calculator(double *h, double *c_p_h)
{
double *p;
*p = (*h) * (*c_p_h);
cout<<"here"<<endl;
return(p);
}
void display()
{
cout<<endl<<endl<<"*********************"<<endl;
cout<<"The salary is "<<salary<<endl;
cout<<"*********************"<<endl;
}
void get_salary()
{
double *s;
s = salary_calculator(&hours, &cash_per_hour);
salary = *s;
}
void get_details()
{
cout<<"********************************"<<endl;
cout<<"WELCOME TO THE SALARY CALCULATOR"<<endl;
cout<<"Please enter your name "<<endl;
cin>>name;
cout<<"Please enter the number of hours worked"<<endl;
cin>>hours;
cout<<"Please enter the rate per hour"<<endl;
cin>>cash_per_hour;
cout<<"***************END****************"<<endl;
}
};
int main()
{
Employee one;
one.get_details();
one.get_salary();
one.display();
return 0;
}
코드를 들여 쓰기 바랍니다. – hetepeperfan
어떤 오류가 있습니까? – simeg
get_details 함수 후 프로그램 작동이 멈 춥니 다 – madridista