Question #31782

Consider the following buggy function:
Employee read_employee()
{
cout << "Please enter the name: ";
string name;
getline(cin, name);
cout << "Please enter the salary: ";
double salary;
cin >> salary;
Employee r(name, salary);
return r;

Expert's answer

#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

string employee;
string name;
double salary;

string Employee read_employee()
{
cout << "Please enter the name: ";
string name;
getline(cin, name);
cout << "Please enter the salary: ";
double salary;
cin >> salary;
Employee r(name, salary);
return r;
}
LATEST TUTORIALS
APPROVED BY CLIENTS