#include<iostream>
using namespace std;
char main()
{
int a;
cout <<"你是猪吗?”<<'\n';
cout <<"如果你是猪,请按1,如果不是,请按2。"<<'\n';
cin >> a;
if (a==1)cout<<"没错,你说对了。"<<endl;
else if (a==2)cout <<"不好意思,你说错了!"<<endl;
else cout <<"请规范答题!" <<endl;
return 0;
}
我希望输入除1以外的数,这个程序重复运行,直到输出1后,程序结束。
是用哪个语句?
#include<iostream>
using namespace std;
char main()
{
int a;
cout <<"你是猪吗?"<<endl;
cout <<"如果你是猪,请按1,如果不是,请按2。"<<'\n';
while(1)
{
cin >> a;
if (a==1)
{
cout<<"没错,你说对了。"<<endl;
break;
}
else if (a==2)
{
cout <<"不好意思,你说错了!"<<endl;
}
else
cout <<"请规范答题!" <<endl;
}
return 0;
}
cin>>a;
while(a != 1)
{
....
cin>>a;
}