I'm not sure if you all need all my files, but I'm getting the following error message when compiling:

productionworker.cpp(8) : error C2440: '=' : cannot convert from 'const char [4]' to 'char'

productionworker.cpp(10) : error C2440: '=' : cannot convert from 'const char [6]' to 'char'

Can anyone help?

#include "ProductionWorker.h"

char ProductionWorker::getNameShift()
{
	char nameShift;

	if (shift == 1)
		nameShift = "Day";
	if (shift == 2)
		nameShift = "Night";
	
	return nameShift;
}

Recommended Answers

All 16 Replies

char is short for character, which means only 1 letter, not multiple.
So doing this char a = "huh" generates an error because a char variable
can only point to one letter.

To solve your problem replace char with std::string, in the return type as well as
the type of nameShift.

I tried to put string in place of char on every file and I got a bunch of errors.

Employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>

//Employee class declaration

class Employee
{
private:
	string employeeName;
	int employeeNumber;
	int hireDate;
public:
	//Default constructor
	Employee()
	{ employeeName = ' ';
	  employeeNumber = 0;
	  hireDate = 0; }
	
	//Constructor
	Employee(std::string name, int number, int date)
	{ set(name, number, date); }

	//Mutator functions
	void set(string, int, int);


	//Accessor functions
	string getEmployeeName() const
	{ return employeeName; }

	int getEmployeeNumber() const
	{ return employeeNumber; }

	int getHireDate() const
	{ return hireDate; }
};
#endif

Employee.cpp

#include "Employee.h"
#include <string>

void Employee::set(string name, int number, int date)
{

}

ProductionWorker.h

#ifndef PRODUCTIONWORKER_H
#define PRODUCTIONWORKER_H
#include "Employee.h"
#include <string>

class ProductionWorker : public Employee
{
private:
	int shift;
	double payRate;
public:
	//Default constructor
	ProductionWorker()
	{ shift = 0;
	  payRate = 0.0; }

	//Constructor
	ProductionWorker(double p)
	{ payRate = p; }

	//Mutator functions
	void setShift(int s)
	{ shift = s; }

	void setPayRate(double p)
	{ payRate = p; }

	//Accessor functions
	string getNameShift();
};
#endif

ProductionWorker.cpp

#include "ProductionWorker.h"
#include <string>

string ProductionWorker::getNameShift()
{
	string nameShift;

	if (shift == 1)
		nameShift = "Day";
	if (shift == 2)
		nameShift = "Night";
	
	return nameShift;
}

main_1.cpp

#include <iostream>
#include <string>
#include "Employee.h"
using namespace std;

int main()
{
	string name;
	int number;
	int date;

	Employee info;

	cout << "Enter the employee's name:  ";
	cin >> name;

	cout << "Enter the employee's number:  ";
	cin >> number;

	cout << "Enter the date the employee was hired:  ";
	cin >> date;

	info.set(name, number, date);

	cout << "The employee's name is " << info.getEmployeeName() << endl;
	cout << "The employee's number is " << info.getEmployeeNumber() << endl;
	cout << "This employee was hired on " << info.getHireDate() << endl;

	return 0;
}

main_2.cpp

#include <iostream>
#include <iomanip>
#include "ProductionWorker.h"
#include <string>
using namespace std;

int main()
{
	int empShift = 0;
	double empPayRate = 0.0;

	ProductionWorker stats;

	cout << "Enter the worker's shift where day shift = 1 and night shift = 2:  ";
	cin >> empShift;

	cout << "Enter the worker's pay rate in decimal format (0.00):  ";
	cin >> empPayRate;

	stats.setShift(empShift);
	stats.setPayRate(empPayRate);

	cout << "This worker has the " << stats.getNameShift() << " shift and" << endl;
	cout << "makes $" << empPayRate << " per hour" << endl;

	return 0;
}

employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(25) : error C2061: syntax error : identifier 'string'
employee.h(29) : error C2146: syntax error : missing ';' before identifier 'getEmployeeName'
employee.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : warning C4183: 'getEmployeeName': missing return type; assumed to be a member function returning 'int'
employee.h(15) : error C2065: 'employeeName' : undeclared identifier
employee.h(21) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(30) : error C2065: 'employeeName' : undeclared identifier
employee.cpp(4) : error C2065: 'string' : undeclared identifier
employee.cpp(4) : error C2146: syntax error : missing ')' before identifier 'name'
employee.cpp(4) : error C2761: 'void Employee::set(void)' : member function redeclaration not allowed
employee.cpp(4) : error C2059: syntax error : ')'
employee.cpp(5) : error C2143: syntax error : missing ';' before '{'
employee.cpp(5) : error C2447: '{' : missing function header (old-style formal list?)
employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(25) : error C2061: syntax error : identifier 'string'
employee.h(29) : error C2146: syntax error : missing ';' before identifier 'getEmployeeName'
employee.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : warning C4183: 'getEmployeeName': missing return type; assumed to be a member function returning 'int'
employee.h(15) : error C2065: 'employeeName' : undeclared identifier
employee.h(21) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(30) : error C2065: 'employeeName' : undeclared identifier
main_1.cpp(23) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(25) : error C2061: syntax error : identifier 'string'
employee.h(29) : error C2146: syntax error : missing ';' before identifier 'getEmployeeName'
employee.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : warning C4183: 'getEmployeeName': missing return type; assumed to be a member function returning 'int'
employee.h(15) : error C2065: 'employeeName' : undeclared identifier
employee.h(21) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(30) : error C2065: 'employeeName' : undeclared identifier
productionworker.h(29) : error C2146: syntax error : missing ';' before identifier 'getNameShift'
productionworker.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.h(29) : warning C4183: 'getNameShift': missing return type; assumed to be a member function returning 'int'
productionworker.cpp(4) : error C2143: syntax error : missing ';' before 'ProductionWorker::getNameShift'
productionworker.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.cpp(6) : error C2146: syntax error : missing ';' before identifier 'nameShift'
productionworker.cpp(6) : error C2065: 'nameShift' : undeclared identifier
productionworker.cpp(9) : error C2065: 'nameShift' : undeclared identifier
productionworker.cpp(11) : error C2065: 'nameShift' : undeclared identifier
productionworker.cpp(13) : error C2065: 'nameShift' : undeclared identifier
employee.h(10) : error C2146: syntax error : missing ';' before identifier 'employeeName'
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(25) : error C2061: syntax error : identifier 'string'
employee.h(29) : error C2146: syntax error : missing ';' before identifier 'getEmployeeName'
employee.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
employee.h(30) : warning C4183: 'getEmployeeName': missing return type; assumed to be a member function returning 'int'
employee.h(15) : error C2065: 'employeeName' : undeclared identifier
employee.h(21) : error C2660: 'Employee::set' : function does not take 3 arguments
employee.h(30) : error C2065: 'employeeName' : undeclared identifier
\productionworker.h(29) : error C2146: syntax error : missing ';' before identifier 'getNameShift'
productionworker.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
productionworker.h(29) : warning C4183: 'getNameShift': missing return type; assumed to be a member function returning 'int'

whew...

in your employee.h, after the #include <string>
insert using std::string;

Thanks. That cleared almost all errors I only have two

employeeproductionworker\main_1.cpp(28) : error C2374: 'info' : redefinition; multiple initialization
employeeproductionworker\main_1.cpp(13) : see declaration of 'info'

Can you show ur current code.

main_1.cpp

#include <iostream>
#include <string>
using std::string;
#include "Employee.h"
using namespace std;

int main()
{
	string name;
	int number;
	int date;

	Employee info;

	//Get the employee's name
	cout << "Enter the employee's name:  ";
	cin >> name;

	//Get the employee's number
	cout << "Enter the employee's number:  ";
	cin >> number;

	//Get the date the employee was hired
	cout << "Enter the date the employee was hired:  ";
	cin >> date;

	//Define info object and initalize it with values entered
	Employee info(name, number, date);

	//Display the results
	cout << "The employee's name is " << info.getEmployeeName() << endl;
	cout << "The employee's number is " << info.getEmployeeNumber() << endl;
	cout << "This employee was hired on " << info.getHireDate() << endl;

	return 0;
}

Ahh, you define the variable "info" twice, one in line 13 and the other in line
28. Just delete line 13.

I'm retarded lol. I deleted it and I get this:

fatal error LNK1169: one or more multiply defined symbols found

Post full error

main_2.obj : error LNK2005: _main already defined in main_1.obj
EmployeeProductionWorker.exe : fatal error LNK1169: one or more multiply defined symbols found

Do you think I should put everything in the main() function from main_2.cpp into main() in main_1.cpp?

You should only have 1 main, 1 entry point! I don't know if you have 2 int main() , but if you do, then delete one of them or transfer on of them to the other.

commented: Thanks for all your help +1

I did that and it works. I only have 1 more problem. I need the program to ask for the employee's name. If the user puts "John Doe" it does not prompt the next question. If they put in "John" it asks for the next question.

#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "ProductionWorker.h"
using namespace std;
using std::string;

int main()
{
	string name;
	int number;
	int date;

	int empShift = 0;
	double empPayRate = 0.0;

	//Create a ProductionWorker object
	ProductionWorker stats;

	//Get the employee's name
	cout << "Enter the employee's name:  ";
	cin >> name;

	//Get the employee's number
	cout << "Enter the employee's number:  ";
	cin >> number;

	//Get the date the employee was hired
	cout << "Enter the date the employee was hired:  ";
	cin >> date;

	//Get the employee's shift
	cout << "Enter the employee's shift where day shift = 1 and night shift = 2:  ";
	cin >> empShift;

	//Get the employee's pay rate
	cout << "Enter the employee's pay rate in decimal format (0.00):  ";
	cin >> empPayRate;

	//Store the employee's shift and pay rate into the stats object
	stats.setShift(empShift);
	stats.setPayRate(empPayRate);

	//Define info object and initalize it with values entered
	Employee info(name, number, date);

	//Display the results
	cout << "\nThe employee's name is " << info.getEmployeeName() << endl;
	cout << "The employee's number is " << info.getEmployeeNumber() << endl;
	cout << "This employee was hired on " << info.getHireDate() << endl;
	cout << setprecision(3);
	cout << "This worker has the " << stats.getNameShift() << " shift and" << endl;
	cout << "makes $" << empPayRate << " per hour" << endl;

	return 0;
}

when getting a name, into a string variable, or any input from into a string variable
if you use getline(cin,someStringVariable) , then it reads the whole line
into the someStringVariable. The problem with yours was that cin stops reading when
it reaches a whitespace. because of that, there could be some input left in the buffer,
and in your case it was, which causes the input to fail. So when getting a name into
a string a variable use getline(cin,name).

lol. I should spend more time trying things before I post lol... I just put it
getline(cin, name);
and I checked here and you said the same thing. Thanks for all your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.