Hello,

I am having the following problem with calling my function to return the salary it calculated depending on the switch statement.

I don't understand the error:
": error C3861: 'getSalary': identifier not found"

double Salary::getSalary()
{
	return salary;
}
void Salary::compute()
{
	cout << "Enter the employee's paycode (-1 to end): ";
	cin >> paycode;
	validatePayCode(paycode);

	while(paycode != -1)
	{
		switch (paycode)
		{
		case 1:
			int fixed;
			cout << "Enter the manager's weekly salary: ";
			cin >> fixed;
			validateDouble(fixed);
			salary = fixed;
		break;

		case 2:
			double hours;
			cout << "Enter hours worked: ";
			cin >> hours;
			validateDouble(hours);

			double wage;
			cout << "Enter the hourly wage: ";
			cin >> wage;
			validateDouble(wage);

			if(hours <= 40)
			salary = hours * wage;
			else
			salary = 40 * wage + (hours - 40) * (wage + (wage/2));

		break;

		case 3:
		int sales;
		cout << "Enter the commission worker's gross weekly sales: ";
			cin >> sales;
			validateDouble(sales);
			salary = 250 + .057 * sales;
		break;

		case 4: 
		int items;
		cout << "Enter the number of items produced by the piece worker: ";
		cin >> items;
		validateInteger(items);

		       cout << "Enter the fixed amount per item: ";
		       cin >> fixed;
		       validateDouble(fixed);
		       salary = fixed * items;
		break;

		} // end switch 
	} // end while
	displayMessage();
} // end compute function

void displayMessage()
{
	cout << "The salary is $" << getSalary() << endl;
}

Recommended Answers

All 4 Replies

Since displayMessage() is not a member of Salary class the compiler is looking for a function names getSalary() that is also not a member of that class.

One way to fix this is to make displayMessage a member of the class Salary::displayMessage()

Hello,

I am having the following problem with calling my function to return the salary it calculated depending on the switch statement.

I don't understand the error:
": error C3861: 'getSalary': identifier not found"

double Salary::getSalary()
{
	return salary;
}


void displayMessage()
{
	cout << "The salary is $" << getSalary() << endl;
}

Is displayMessage() part of the Salary class. If so, add Salary:: to it as you did with getSalary:


void Salary::displayMessage()
{
cout << "The salary is $" << getSalary() << endl;
}

Since displayMessage() is not a member of Salary class the compiler is looking for a function names getSalary() that is also not a member of that class.

One way to fix this is to make displayMessage a member of the class Salary::displayMessage()

I was wondering why it was complaining about get salary instead, thank you for the explanation, it was a silly mistake, but its good to know the logic behind it.

Is displayMessage() part of the Salary class. If so, add Salary:: to it as you did with getSalary:

void Salary::displayMessage()
{
    cout << "The salary is $" << getSalary() << endl;
}

end quote.

Thank you :)

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.