这是我的代码,当x <y时有效。但是当x> y时不是。我怎样才能解决这个问题?我知道问题在while循环内,并且我尝试了很多不同的方法,但无法解决问题。
int main()
{
int x,y;
int total = 0;
cout<<"Please give me an integer: ";
cin >> x;
cout<<"Please give me another integer: ";
cin >> y;
int counter = x;
while(counter <= y ){
total += counter;
++counter;
}
cout << "The total of the numbers " << total<<endl;
}
Run Code Online (Sandbox Code Playgroud) c++ ×1