嗨,我刚刚在我的sem休息时进行编码,现在练习写了一个简单的奇数或者甚至是赌注,所以我做了一个小UI如下所示
int Option()
{
int UI;
bool Conformation = 0;
while (Conformation == 0)
{
cout << "For odd enter 1 , for even enter 2\n Insert : ";
cin >> UI;
Conformation = 0;
switch (UI)
{
case 1:
cout << "You have selected odd \n are you sure?\n 1.Yes 2.NO \n Insert :";
cin >> Conformation;
break;
case 2:
cout << "You have selected even \n are you sure? 1.Yes 2.NO \n Insert :";
cin >> Conformation;
break;
default:
cout << "Invalid entery please enter another value\n";
Conformation = 0;
break;
}
}
return UI;
}
我希望它循环通过第8行“cin&gt;&gt; UI;”当Conformation = 0时,它只是跳过任何形式的“cin”
提前谢谢。
答案 0 :(得分:0)
你有:
cout << "You have selected odd \n are you sure?\n 1.Yes 2.NO \n Insert :";
cin >> Conformation;
由于1
类型为2
,因此Confirmation
或Confirmation
对bool
的使用极有可能使您失望。
我建议将Confirmation
的类型更改为int
。