不知道为什么while循环不起作用,尽管我认为我指定了代码中先前输入的内容。
#include <iostream>
using namespace std;
int main()
{
do
{
cout<<"1. \tOpen File"<<endl;
cout<<"2. \tClose File"<<endl;
cout<<"3. \tExit"<<endl;
int input;
cin >> input;
cout<<"Select and option: "<<endl;
switch(input)
{
case 1:
cout<<"Opening File"<<endl;
break;
case 2:
cout<<"Closing File"<<endl;
break;
case 3:
cout<<"Exiting..."<<endl;
break;
default:
cout<<"Invalid Entry"<<endl;
}
}
while (input < 1 || input > 3);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望程序会询问我的输入,如果输入的类型错误,程序会重复执行
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |