I try to write an employee main file and met with one problem. I can not add an answer for the second question which I try to promt from user. If I change the places between the first question: cout << "\nEnter a percent raise: "; and the second question: cout << "\nEnter a new surname: "; everything works fine, but it not what I need. Could you please help me ?
#include <iostream>
#include "Employee.h"
#include <string>
using namespace std;
int main()
{
//Create two employees
Employee e1{ "John", "Doe", 1234.56 };
Employee e2{ "Jane", "Jones", 7890.12 };
//Display employee's info
cout << "Employee e1: " << e1.getName() << ", " << e1.getSurname() << ", " << e1.getSalary() << endl;
cout << "Employee e2: " << e2.getName() << ", " << e2.getSurname() << ", " << e2.getSalary() << endl;
//Give a permanent raise to both employee
cout << "\nEnter a percent raise: ";
double annualraise;
cin >> annualraise;
e1.setRaise(annualraise), e2.setRaise(annualraise);
cout << "Employee e1: " << e1.getName() << ", " << e1.getSurname() << ", " << e1.getSalary() << endl;
cout << "Employee e2: " << e2.getName() << ", " << e2.getSurname() << ", " << e2.getSalary() << endl;
//Change Jane's last name to "Doe"
cout << "\nEnter a new surname: ";
string theSurname;
getline(cin, theSurname);
e2.setSurname(theSurname);
cout << "Employee e2: " << e2.getName() << ", " << e2.getSurname() << ", " << e2.getSalary() << endl;
return 0;
}
//IMPLEMENTATION FILE (Employee.cpp)
#include "Employee.h"
#include <string>
using namespace std;
#include <iostream>
Employee::Employee(std::string employeeName, std::string employeeSurname, double monthlySalary)
:name{employeeName}, surname{employeeSurname}, salary{monthlySalary}
{
}
void Employee::setName(std::string employeeName)
{
name = employeeName;
}
string Employee::getName() const
{
return name;
}
void Employee::setSurname(std::string employeeSurname)
{
surname = employeeSurname;
}
string Employee::getSurname() const
{
return surname;
}
void Employee::setRaise(double raise)
{
if (raise >= 0)
{
salary = (salary * raise) + salary;
}
else
cout << "Wrong integer";
}
double Employee::getSalary() const
{
return salary * 12;
}