怎么使c++程序不退出,继续输入运行?

有个c++程序:#include <iostream>using namespace std;int main(){ int age; cout<<"Please enter your age:"; cin>>age;
if (age>=18) { cout<<"You can vote!"<<endl; } else { cout<<"\a\a\a\a\a\a\a\a\a\aToo young to vote!!"<<endl; } getchar(); system("pause");}怎么样使得它一直能输入年龄,然后一直判断下去呢?

加循环,或者在程序最后继续调用输年龄这个函数。
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-11-10
很简单啊 加一个死循环就OK了 呵呵:#include <iostream>using namespace std;int main(){ int age; while(1){cout<<"Please enter your age:"; cin>>age;<br _extended="true">if (age>=18) { cout<<"You can vote!"<<endl; } else { cout<<"\a\a\a\a\a\a\a\a\a\aToo young to vote!!"<<endl; } }getchar(); system("pause");}
第2个回答  2013-11-10
把cin>> 改成agewhile(cin>>age),后面的都大括号括起来~
相似回答