Keeping getting no suitable conversion function from "std::string" to "double" exists

#include <iostream>
#include <string>
#include <iomanip>
#include <stdexcept>
#include <sstream>

using namespace std;

class Employee
{
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;

public:
Employee();
Employee(string, string, char, int, double);
double calculatePay();
void displayEmployee();
string getFirstName();
string setFirstName(string);
string getLastName();
string setLastName(string);
char getGender();
void setGender(char);
int getDependents();
int setDependents(int);
double getAnnualSalary();
double setAnnualSalary(double);
void DisplayApplicationInformation();
void DisplayDivider(string);
string GetInput(string);
void TerminateApplication();
};

Employee::Employee()
{
firstName = "Not given";
lastName = "Not given";
gender = ('U');
dependents = 0;
annualSalary = 20000;
};

Employee::Employee(string first, string last, char gen, int depends, double anSalary)
{
firstName = first;
lastName = last;
gender = gen;
dependents = depends;
annualSalary = annualSalary;
};

string Employee::getFirstName()
{
return firstName;
}

string Employee::setFirstName(string)
{
return firstName;
}

string Employee::getLastName()
{
return lastName;
}

string Employee::setLastName(string)
{
return lastName;
}

char Employee::getGender()
{
return gender;
}

void Employee::setGender(char)
{
gender = gender;
}

int Employee::getDependents()
{
return dependents;
}

int Employee::setDependents(int)
{
return dependents;
}

double Employee::getAnnualSalary()
{
return annualSalary ;
}

double Employee::setAnnualSalary(double)
{
return annualSalary;
}

void Employee::displayEmployee()
{
cout << "Employee Name: " << firstName << " "<< lastName << endl;
cout << "Employee Gender: " << gender << endl;
cout << "Employee Dependents: " << dependents << endl;
cout << "Empoyee Annual Salary: " << annualSalary << endl;
cout << "Annual Salary:\t" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
cout << "Employee Weekly Salary: " << annualSalary/52 << endl << endl;
};

double Employee::calculatePay()
{
return annualSalary/52;
};


void DisplayApplicationInformation()
{
cout << "Welcome the Basic User Interface Program" << endl;
cout << "CIS247, Week 2 Lab" << endl;
cout << "Name: Alicia Long" << endl << endl;
};
void DisplayDivider(string outputTitle)
{
cout << "**********"<< outputTitle << "**********" << endl << endl;
};

string GetInput(string inputType)
{
string strInput;
cout << "Enter the Employee " << inputType << endl;
cin >> strInput;
return strInput;
}

void TerminateApplication()
{
cout << "Thank you for using the Basic User Interface program" << endl;
}

void main()
{

DisplayApplicationInformation();
DisplayDivider("Employee 1");
Employee Employee1;

string firstName = GetInput("First Name");
Employee1.setFirstName(firstName);

string lastName = GetInput("Last Name");
Employee1.setLastName(lastName);

string dependents = GetInput("Dependent");
dependents = atoi(dependents.c_str());
Employee1.setDependents(dependents);

string annualSalary = GetInput("Annual Salary");
annualSalary = atof(annualSalary.c_str());
Employee1.setAnnualSalary(annualSalary);

Employee1.displayEmployee();

TerminateApplication();
}
When you say Foo bar; you are declaring the variable `bar' being of type `Foo'
For as long as bar lives, it will be a Foo. It can't be anything else, just Foo.

1
2
3
string dependents = GetInput("Dependent"); //dependents is a string
dependents = atoi(dependents.c_str()); //still a string
Employee1.setDependents(dependents); //still a string 
and you are trying to pass a `string' when your function expected a number.

1
2
string dependents = GetInput("Dependent");
Employee1.setDependents( atoi(dependents.c_str()) );



Because doing
1
2
std::string s;
s = 'c';
is valid, you didn't receive any complains when assigning the result of atoi()
THANK U SO MUCH!!!!!I really appreciated it
Topic archived. No new replies allowed.