这是我想要实现的:
#include <iostream>#include <string>#include <sstream>using namespace std;int main(){ int n; cout<<"Enter numbers. Press 5 to stop: "; cin>>n; bool tr=true; while(tr) { if(n!=5) cout<<"You entered "<<n; //How to make it return again,since its false? I keep getting infinite loops :( ; else tr=false; } return 0;}解决方法 您需要在while循环中提示用户,以便它在每次迭代中发生:
int n;bool tr = true;while(tr){ cout << "Enter numbers. Press 5 to stop: "; cin >> n; if(n!=5) { cout << "You entered " << n; } else { tr = false; }}总结
以上是内存溢出为你收集整理的c – 如果条件为真,则返回if条件,如果为真,则返回全部内容,希望文章能够帮你解决c – 如果条件为真,则返回if条件,如果为真,则返回所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)