#include<iostream>#include<stdlib.h>#include<math.h>using namespace std;int main(){ int n; int a; int b; int c; cout << " 1.加法运算\n"; cout << " 2.减法运算\n"; cout << " 3.乘法运算\n"; cout << " 4.除法运算\n"; cout << "Please select a type:\n"; cin >> n; if (n = 1) { cout << "请输入两个数:\n"; cin >> a; cin >> b; c = a + b; cout << "c=" << c << endl; } if (n = 2) { cout << "请输入两个数:\n"; cin >> a; cin >> b; c = a - b; cout << "c=" << c << endl; } if (n = 3) { cout << "请输入两个数:\n"; cin >> a; cin >> b; c = a * b; cout << "c=" << c << endl; } if (n = 4) { cout << "请输入两个数:\n"; cin >> a; cin >> b; c = a / b; cout << "c=" << c << endl; } system("pause");}
1 回答
AAnonymous
TA贡献62条经验 获得超31个赞
if (n = 1)
it will always be TRUE, cause it's assignment statement, n will be 1 which is not 0 (TRUE).
you should use ` if (n == 1) `
also ` n == 2 / 3 / 4 `
- 1 回答
- 0 关注
- 789 浏览
添加回答
举报
0/150
提交
取消