需要有关在 C++ 中的函数 display() 上查找未定义引用的帮助
Need help on finding an undefined reference on function display() in C++
我的任务目标是将美元转换为欧元。我需要做的就是提示用户输入,然后使用函数获取输出 我是编码新手,对于我的生活,我找不到我在声明这个函数时出错的地方。任何建议都值得赞赏。
#include <iostream>
using namespace std;
double getmoney();
double convert();
double display();
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
getmoney();
display();
return 0;
}
double getmoney()
{
double money;
cout << "Please enter the amount in US Dollars: ";
cin >> money;
return money;
}
double convert(double money)
{
double euros;
euros = money * 1.41;
return euros;
}
double display(double money)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
double salad = convert(money);
cout << getmoney() << endl;
if (money >= 0)
cout << "Euros: " << salad;
else (money < 0);
cout << "Euros: " << "(" << salad << ")";
return 0;
}
首先,您将 display 声明为一个不接受任何参数的函数。
double display();
但是,当您定义函数时,该函数将采用双精度类型的参数。
double display(double money)
声明和定义应匹配,以便编译器知道在代码中使用函数时要跳转哪个函数。
在您的情况下,由于声明和定义不同,当您在main()函数中使用display()时,编译器不知道在哪里跳转。因此未定义的参考错误。
名为"display"的函数在顶部声明为在函数调用中没有参数。
double display();
然后稍后你定义这个函数,就像它应该接收一个参数一样。
double display(double money);
编译器不知道如何处理这些冲突,因此会将其视为第一个没有定义的函数。
[编辑:在我看到几乎相同的第一个答案后立即发布]
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 在C++中查找文件
- 需要帮助查找内存泄漏
- 需要一些帮助来查找我的程序中的逻辑错误
- 需要有关在 C++ 中的函数 display() 上查找未定义引用的帮助
- 需要帮助从12个字节生成新的24字节RGB查找阵列,或者是一种更好的编码方法
- 需要帮助查找内存泄漏
- 具有查找表的可选帮助的对象查找,如果未使用,则必须对其进行优化
- 在没有字符串或字符帮助的情况下查找数字的反面(例如:2500 reverse 0025)
- 请帮助查找错误
- C++帮助:使用数组和循环在文本中查找单词
- 需要帮助查找Prime Emirp C++中的错误
- 将每个单词的第一个字符大写-帮助查找我的错误
- 在布尔矩阵中查找唯一的行(帮助解析std::string的垃圾输出)
- 需要帮助编写一个函数来查找n维数组中的最大值和最小值
- 有哪些工具可以帮助查找句柄的内存泄漏
- 帮助,澄清我对不合格名称查找的疑问:ISO n3290草案
- MPI帮助查找n个数字的最大值
- 需要帮助查找内存泄漏
- 帮助实现在结构体数组中查找名称的二进制搜索