我是一个新的贡献者,在这里我正在尝试制作一个简单的计算器,但我的代码中有错误。当我编译代码时,我得到:
Error: C:\Users\IJLAL\Documents\collect2.exe [Error] ld returned 1 exit status while compiling
如果有帮助,这里是我在 Dev C++ 中按下编译按钮或 F11 时的错误屏幕截图:
这是我的代码:
#include<iostream>
using namespace std;
void fun(float a, float b);
int main()
{
float a, b, sum, sub, mul, divide, mod;
char op;
//operands and operators are enterd by the user
cout<<"Enter any two operands with operator=";
cin>>a>>op>>b;
fun(a, b);
return 0;
}
void op(float a, float b)
{
if(a+b)
{
float sum=a+b;
cout<<"\nAddition of two numbers is="<<sum;
}
else if(a-b)
{
float sub=a-b;
cout<<"\nSubtraction of two numbers is="<<sub;
}
else if(a*b)
{
float mul=a*b;
cout<<"\nMultiplication of two numbers is="<<mul;
}
else if(a/b)
{
float divide=a/b;
cout<<"\nDivision of two number is="<<divide;
}
else
{
cout<<"\nInvalid operator.......";
}
}
请告诉我这个问题的解决方案,以便我可以成功编译代码。如果有任何更好的解决方案可以在 初学者级别 制作一个简单的计算器,请在回答中提及。
原文由 Ijlal Hussain 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用附加功能来制作更好的计算器。您可以使用此代码。希望此代码对您有所帮助。
标头
<iomanip>
是C++
标准库的输入/输出库的一部分,而<math.h>
在我们执行数学运算时使用。