为了账号安全,请及时绑定邮箱和手机立即绑定

运行结果不对,哪里出错了?

运行结果不对,哪里出错了?

C++
TiAmo_YF 2018-09-08 19:22:12
#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 `

查看完整回答
反对 回复 2018-09-08
  • 1 回答
  • 0 关注
  • 789 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信