我的代码存在问题,我需要变量" y"存储a的先前值,但我找不到解决方案
#include <iostream>
using namespace std;
int main() {
int a;
int b;
int x = 0;
int y;
cout << "please enter two numbers then press <Enter>" << endl;
cin >> a && y;
cin >> b;
while (a <= b){
cout << a << endl;
a++;
x++;
}
cout << "There were " << x << " numbers between " << y << " and " << b << endl;
return 0;
}
答案 0 :(得分:0)
你需要这样的东西:
cout << "please enter two numbers then press <Enter>" << endl;
cin >> a >> y;
请注意,这两个值应以空格分隔。
从代码中看,您输入的是3个变量:
cin >> a;
cin >> y;
cin >> b;
如果您想将副本放入y,请尝试以下方法:
cin >> a; y = a;
cin >> b;