gpt4 book ai didi

C++ 计算器没有像我想象的那样工作

转载 作者:行者123 更新时间:2023-11-28 02:46:07 24 4
gpt4 key购买 nike

<分区>

为什么我的计算器不能正常工作? Visual Studios 只询问我是否要使用上次成功的构建。

我无法查看用户输入的计算结果是否为字符串吗?

这是我的代码:

#include <iostream>

using namespace std;

int main() {

int operation;
int a;
int b;

cout << "Choose an operation:\n";
cout << "+ = Addition\n";
cout << "- = Subtraction\n";
cout << "* = Multiplication\n";
cout << "/ = Division\n";

cin >> operation;

if (operation == "+") {
cout << "Enter a number! \n";
cin >> a;

cout << "Enter another number! \n";
cin >> b;

sum = a + b;
cout << sum;
}
if (operation == "-") {
cout << "Enter a number! \n";
cin >> a;

cout << "Enter another number! \n";
cin >> b;

sum = a - b;
cout << sum;
}
if (operation == "*") {
cout << "Enter a number! \n";
cin >> a;

cout << "Enter another number! \n";
cin >> b;

sum = a * b;
cout << sum;
}
if (operation == "/") {
cout << "Enter a number! \n";
cin >> a;

cout << "Enter another number! \n";
cin >> b;

sum = a / b;
cout << sum;
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com