编写程序完成一个简单计算器。通过键盘输入合法的四则运算表达式,然后输出表达式及其计算结果。是否继续进行计算,由用户确认:”是否继续答题(Y/N)?”,输入Y继续,N退出
我写的代码
```c++
#include <iostream>
using namespace std;
int main()
{
char op;
int num1, num2, result,r=0,c,i;
while (i = 0, i <= 100)
{
cin >> num1 >> op >> num2;
cin >> r;
switch (op)
{
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
default: cout << "运算符非法." << endl;
}
cout << num1 << op << num2 << "=" << r << endl;
if (r == result) cout << "你答对了" << num1 << op << num2 << "=" << r << endl;
if (r != result) cout << "你答错了" << num1 << op << num2 << "=" << result << endl;
cout << "输入y/n" << endl;
cin >> c;
if (c == 'y') continue;
else if (c != 'n') break;
}
return 0;
}
可以正常运行计算但没办法进行是否继续的判断
如图
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/44813878856610.png "#left")
因为我是新手,只学到头文件iostream的,希望各位大神可以迁就一下,帮我解答一下
谢谢!
```c++