好的,我是一个完整的 C++ 菜鸟(我昨天才开始学习),我正在尝试编写一个简单的计算器程序。我用记事本写的,但是当我尝试编译它时,cmd产生了很多错误,这很有趣。谁能告诉我我做错了什么?
这是我的代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
double num1;
double num2;
string operator;
double num3;
cout<<"Enter your first number"<<endl;
cin<<num1;
cout<<"Enter the operator"<<endl;
cin<<operator;
cout<<"Enter the next number"<<endl;
cin<<num2;
if(operator=="/"&&num2==0)
{
cout<<"You are attempting to divide by 0. This is impossible and causes the destruction of the universe. However, the answer is infinity"<<endl;
}
if(operator=="+")
{
num3 = num1+num2;
}
else if(operator=="-")
{
num3 = num1-num2;
}
else if(operator=="*"||operator=="x"||operator=="X")
{
num3 = num1*num2;
}
else
{
num3 = num1/num2;
}
return 0;
}