我的四个函数都有相同的错误.C2064:术语的计算结果不是采用3个参数的函数



我正在为class做一个项目。到目前为止,我已经完成了它,除了错误2064之外,没有其他编译器错误。我得到的确切错误如下。我已经为此工作了几个小时,现在我正在参考我的书,我看了其他帖子,我仍然不知所措。非常感谢您的帮助。

1>C: \Users\tsch\OneDrive \Desktop\Project 07\Project 07.cpp(75,73(:错误C2064:术语未评估为采用3个参数的函数

1>C: \Users\tsch\OneDrive \Desktop\Project 07\Project 07.cpp(88,76(:错误C2064:术语未计算为采用2个参数的函数

1>C: \Users\tsch\OneDrive \Desktop\Project 07\Project 07.cpp(107,55(:错误C2064:术语未计算为采用5个参数的函数

1>C: \Users\tsch\OneDrive \Desktop\Project 07\Project 07.cpp(124,48(:错误C2064:术语的计算结果不是采用4个参数的函数1>完成建筑工程";项目07.vcxproj"——失败。==========生成:0成功,1失败,0最新,0跳过==========

#include <iostream>
#include <iomanip>
using namespace std;
double grossPay(int number, double hours, double pay); // hourly function
double grossPay(int number, double salary); // salary function
double grossPay(int company, int project, int number, double hours, double pay);  // contract function
double grossPay(int institution, int department, double hours, double pay); // intern function

int main() {
// prompt user for type of employee and give EOF instructions.
cout << "Enter '1' for hourly. Enter '2' for salaried." << endl;
cout << "Enter '3' for contracter. Enter '4' for intern." << endl;
cout << "If result is -1, the input was invalid, please input correct employee hours." << endl;
cout << endl;
cout << "Terminate input by using <ctrl> z on Windows then press enter." << endl;
cout << "Terminate input by using <ctrl> z on UNIX / Linux / Mac OS X then press enter." << endl;
int employeeType{ 0 };
int employeeNumber{ 0 };
double grossPay{ 0 };
double overtimePay{ 0 };
// salaried
double employeeSalary{ 0 };
// hourly
double hoursWorked{ 0 };
double payRate{ 0 };
// contractor
int companyNum{ 0 };
int projectNum{ 0 };
// intern
int schoolCode{ 0 };
int departmentCode{ 0 };
while (cin >> employeeType) {
switch (employeeType) {
case 1:
// HOURLY employee prompts and output
cout << "Enter employee number: " << endl;
cin >> employeeNumber;
cout << "Enter number of hours employee worked: " << endl;
cin >> hoursWorked;
cout << "Enter employees pay rate: " << endl;
cin >> payRate;
cout << setprecision(2) << fixed;
cout << "Gross pay of employee including overtime, is $" << grossPay(employeeNumber, hoursWorked, payRate) << endl;
cout << endl;
break;
case 2:
// SALARIED employee prompts and output
cout << "Enter employee number: " << endl;
cin >> employeeNumber;
cout << "Enter employees salary: " << endl;
cin >> payRate;
cout << setprecision(2) << fixed;
cout << "Gross pay of employee" << employeeNumber << "is $" << grossPay(employeeNumber, payRate) << endl;
cout << endl;
break;
case 3:
// CONTRACT employee prompts and output
cout << "Enter company number: " << endl;
cin >> companyNum;
cout << "Enter project number: " << endl;
cin >> projectNum;
cout << "Enter employee number: " << endl;
cin >> employeeNumber;
cout << "Enter number of hours employee worked: " << endl;
cin >> hoursWorked;
cout << "Enter employees pay rate: " << endl;
cin >> payRate;
cout << setprecision(2) << fixed;
cout << "Gross pay of contractor is $" << grossPay(companyNum, projectNum, employeeNumber, hoursWorked, payRate) << endl;
cout << endl;
break;
case 4:
// INTERN prompts and output
cout << "Enter institution code: " << endl;
cin >> schoolCode;
cout << "Enter department code: " << endl;
cin >> departmentCode;
cout << "Enter number of hours employee worked: " << endl;
cin >> hoursWorked;
cout << "Enter employees pay rate: " << endl;
cin >> payRate;
cout << setprecision(2) << fixed;
cout << "Gross pay of intern $" << grossPay(schoolCode, departmentCode, hoursWorked, payRate) << endl;
cout << endl;
break;
}
cout << "Enter '1' for hourly. Enter '2' for salaried." << endl;
cout << "Enter '3' for contracter. Enter '4' for intern." << endl;
cout << endl;
}
cout << endl;
cout << "Thank you for using this program. " << endl;
}

// hourly function
double grossPay(int number, double hours, double pay) {
double hourlyWeek{ 0 };
while (hours > 0 && hours <= 50.00) {
if (hours > 40.00) {
hourlyWeek = ( ( pay * 40.00) + ( hours - 40.00) * (pay *1.50) );
}
else {
hourlyWeek = (hours * pay);
}
}
while (hours > 50.00) {
hourlyWeek = -1;
}
return hourlyWeek;
}
// salary function
double grossPay(int number, double salary) {
double salaryWeek{ 0 };
salaryWeek = (salary * 40);
return salaryWeek;
}

//contractor function
double grossPay(int company, int project, int number, double hours, double pay) {
double contractWeek{ 0 };
while (hours > 0 && hours <= 40.00) {
contractWeek = ((pay * 40.00) + (hours - 40.00) * (pay * 1.50));
}

while (hours > 40.00) {
contractWeek = -1;
}
return contractWeek;
}
// intern function
double grossPay(int institution, int department, double hours, double pay) {
double internWeek{ 0 };
while (hours > 0 && hours <= 20.00) {
if (hours > 15.00) {
internWeek = ((pay * 40.00) + (hours - 40.00) * (pay * 1.25));
}
else {
internWeek = (hours * pay);
}
}
while (hours > 20.00) {
internWeek = -1;
}
return internWeek;
}

有一个声明为double grossPay{ 0 };的局部变量,它隐藏了grossPay()的函数声明。换句话说,由于grossPay有一个局部定义,编译器将不使用函数定义。该变量似乎未使用,删除该行就可以了。

作为一个更通用的提示,使用这个经验法则更容易避免这些类型的名称冲突:名称值与名词,函数与动词。在这种情况下,这可能涉及将函数grossPay()重命名为getGrossPay()calculateGrossPay()

最新更新