In this code I ask the user for his name, hours worked and rate per hour, then multiply both to get his salary. I am doing this via a pointer function but for some reason when the program goes to the calculate_salary function, it ends with an error. What is wrong and why is this happening?
#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
<< "The salary is " << salary << endl
<< "*********************" << 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;
}