能进行四则运算
能连续多次计算
能识别符号错误
暂不能识别数字错误
暂不能识别加减和乘除的计算顺序
文件下载地址:(4条消息) 幼儿园级四则整数计算器.zip-C/C++文档类资源-CSDN下载
代码如下:
#include <iostream>
using namespace std;
int main()
{
std::cout << "计算器\n";
while (1) {
int numa , numb , numc;
char fuhao;
cout << "数字\n";
(cin >> numa);
huidao:cout << "符号 需为加减乘除或等号\n";
(cin >> fuhao);
if (fuhao == '+') {
cout << "下一个数字\n";
(cin >> numb);
numc = numa + numb ;
numa = numc;
goto huidao;
}
else if (fuhao == '-') {
cout << "下一个数字\n";
(cin >> numb);
numc = numa - numb;
numa = numc;
goto huidao;
}
else if (fuhao == '*') {
cout << "下一个数字\n";
(cin >> numb);
numc = numa * numb;
numa = numc;
goto huidao;
}
else if (fuhao == '/') {
cout << "下一个数字\n";
(cin >> numb);
numc = numa / numb;
numa = numc;
goto huidao;
}
else if (fuhao == '=') {
cout << "得数是" << numa << endl ;
}
else {
cout << "傻逼,这都能输错\n";
goto huidao;
}
}
}
注:如使用Visual Studio请在命令行程序项目下编写,空项目好像不会有显示。
|