C++ 编辑了大多数错误,现在已编译但未运行,我做错了什么? #包括 #包括 #包括 #包括 使用std::cout; 使用std::cin; 使用std::endl; 使用std::string; 使用std::setprecision; 使用std::fixed; //功能原型 void getInput(字符串和双精度); 无效计算轴(双精度、双精度、双精度和双精度); 作废calcnetPay(双倍、双倍、双倍、双倍); 无效显示信息(字符串、双精度、双精度、双精度); int main() { //声明常量和变量 常数双FWT_率=.2; 常数双FICA_率=.08; 字符串dname=“”; 双D标准=0.0; 双dfwtTax=0.0; 双dficaTax=0.0; 双倍dnetPay=0.0; //以小数点后两位的定点表示法显示输出 不能以偏概全; } 空隙钙质轴(双倍法拉利、双倍弗拉特、双倍榕酸、, 双倍和预扣税、双倍和incomeTax) { 预扣税=F法定*税率; incomeTax=f唾液酸盐*FicaRate; } 作废calcnetPay(双倍和网付、双倍每周工资、双倍fwtTax、, 双倍(X) { 网支付=每周一次-fwtTax-fitax; } 无效显示信息(字符串dname、双dfwtTax、双DFCATAX、, 双倍dnetPay) { cout
这些不是标准的库函数,您知道它们来自哪里吗?可能是您的环境/编译器中的某些东西C++ 编辑了大多数错误,现在已编译但未运行,我做错了什么? #包括 #包括 #包括 #包括 使用std::cout; 使用std::cin; 使用std::endl; 使用std::string; 使用std::setprecision; 使用std::fixed; //功能原型 void getInput(字符串和双精度); 无效计算轴(双精度、双精度、双精度和双精度); 作废calcnetPay(双倍、双倍、双倍、双倍); 无效显示信息(字符串、双精度、双精度、双精度); int main() { //声明常量和变量 常数双FWT_率=.2; 常数双FICA_率=.08; 字符串dname=“”; 双D标准=0.0; 双dfwtTax=0.0; 双dficaTax=0.0; 双倍dnetPay=0.0; //以小数点后两位的定点表示法显示输出 不能以偏概全; } 空隙钙质轴(双倍法拉利、双倍弗拉特、双倍榕酸、, 双倍和预扣税、双倍和incomeTax) { 预扣税=F法定*税率; incomeTax=f唾液酸盐*FicaRate; } 作废calcnetPay(双倍和网付、双倍每周工资、双倍fwtTax、, 双倍(X) { 网支付=每周一次-fwtTax-fitax; } 无效显示信息(字符串dname、双dfwtTax、双DFCATAX、, 双倍dnetPay) { cout,c++,C++,这些不是标准的库函数,您知道它们来自哪里吗?可能是您的环境/编译器中的某些东西 您需要与库链接,在visual studio中,请参见属性->链接器->输入->其他依赖项,在uinx上,您必须将“-lnameoflibrary”传递给编译器您的代码引用的是它未提供的函数。(这只是一个链接错误,因为这些函数很可能由您可能正在链接的其他库提供。) (没有任何代码发布)您可能有一个单独的头文件,用于定义getInput和displayInfo的原型。请确保getInput和displayInfo的定义
您需要与库链接,在visual studio中,请参见属性->链接器->输入->其他依赖项,在uinx上,您必须将“-lnameoflibrary”传递给编译器您的代码引用的是它未提供的函数。(这只是一个链接错误,因为这些函数很可能由您可能正在链接的其他库提供。) (没有任何代码发布)您可能有一个单独的头文件,用于定义getInput和displayInfo的原型。请确保getInput和displayInfo的定义实际上与这些原型匹配!注意
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::setprecision;
using std::fixed;
//function prototypes
void getInput(string &, double);
void calcFedTaxes(double , double, double &, double &);
void calcnetPay(double &, double , double, double);
void displayInfo(string, double, double, double);
int main()
{
//declare constants and variables
const double FWT_RATE = .2;
const double FICA_RATE = .08;
string dname = "";
double dsalary = 0.0;
double dfwtTax = 0.0;
double dficaTax = 0.0;
double dnetPay = 0.0;
//display output in fixed-point notation with two decimal places
cout << fixed << setprecision(2);
//call function to get input and calculate salary and taxes
void getInput(string dname, double dsalary, double dnetPay);
void calcFedTaxes(double Fsalary, double FwtRate, double FicaRate,
double & withholdingTax, double & incomeTax);
void calcnetPay(double & netPay, double weeklySalary, double fwtTax,
double ficaTax);
void displayInfo (string dname, double dfwtTax, double dficaTax,
double dnetPay);
system ("pause");
} //end call function
//*****function definitions*****
void getInput(string iname, double isalary)
{
//enter input items
cout << "Enter name: ";
cin >> iname;
cout << "weekly salary: ";
cin >> isalary;
}
void calcFedTaxes (double Fsalary, double FwtRate, double FicaRate,
double & withholdingTax, double & incomeTax)
{
withholdingTax = Fsalary * FwtRate;
incomeTax = Fsalary * FicaRate;
}
void calcnetPay(double & netPay, double weeklySalary, double fwtTax,
double ficaTax)
{
netPay = weeklySalary - fwtTax - ficaTax;
}
void displayInfo(string dname, double dfwtTax, double dficaTax,
double dnetPay)
{
cout << "name: " << dname;
cout << "With holding Tax: " << dfwtTax;
cout << "With holding Fica: "<<dficaTax;
cout << "Net pay: " <<dnetPay;
cin>> dnetPay;
//end of displayInfo function
return;
}
不同于
void getInput(std::string &foo, double &bar)
当然,还有
void getInput(std::string foo, double bar)
在main
中
void getInpoot(std::string &foo, double &bar)
不会做你认为它会做的事
您所做的是为函数提供原型。这不会生成代码,也不会调用任何函数
你可能是说
//call function to get input and calculate salary and taxes
void getInput(string dname, double dsalary, double dnetPay);
void calcFedTaxes(double Fsalary, double FwtRate, double FicaRate,
double & withholdingTax, double & incomeTax);
void calcnetPay(double & netPay, double weeklySalary, double fwtTax,
double ficaTax);
void displayInfo (string dname, double dfwtTax, double dficaTax,
double dnetPay);
诸如此类。您试图调用的这些函数与您实际定义的函数不匹配,您还必须修复这些函数。随便一看,我注意到两个明显的错误 第一个是
getInput()
原型需要引用,但定义不需要
第二个问题在您看到它后会更加明显。一个简单的输入错误,函数名在displayInfo()
定义中缺少一个“a”
void getInput(string &, double &) ;
void getInput(string iname , double isalary)
在main()中,您只是原型函数,而不是调用它们:
void displyInfo(string dname, double dfwtTax, double dficaTax,
double dnetPay)
定义了一个函数,现在需要调用它:
//call function to get input and calculate salary and taxes
void getInput(string dname, double dsalary, double dnetPay);
也就是说,您的代码令人困惑。让我们看看代码中当前对getInput的三个引用:
getInput(dname, dsalary, dnetPay);
您有两个原型,它们的签名与您的函数定义不同。在清理之前,您将继续遇到问题。这是一个链接错误。请说出您正在使用的编译器和库的名称。抱歉-这里是include#include#include#include#嗯,您呼叫
系统
谁se prototype位于
中。即使它通过另一个标题被拉入,或者在没有合适的原型的情况下工作,您仍然应该#包含正确的标题。谢谢,我正在进行修复,我马上回来,我注意到我把事情搞砸了!:)
getInput(dname, dsalary, dnetPay);
void getInput(string &, double);
void getInput(string dname, double dsalary, double dnetPay);
void getInput(string iname, double isalary) { ... }