【发布时间】:2020-07-29 08:51:40
【问题描述】:
#include <iostream>
#include <vector>
using namespace std;
int main() {
char selection {};
do {
cout<<"\n---------------"<<endl;
cout<<"1 do this "<<endl;
cout<<"2 do that "<<endl;
cout<<"3 do something else "<<endl;
cout<<"q Quit "<<endl<<endl;
cout<<"Enter your selection : ";
cin>>selection;
if (selection=='1')
cout<<"You chose 1 -- doing this "<<endl;
else if (selection=='2')
cout<<"You chose 2-- doing that "<<endl;
else if (selection=='3')
cout<<"You chose 3-- doing something else "<<endl;
else if (selection=='Q'||selection=='q')
cout<<"Goodbye! "<<endl;
else
cout<<"Unknown value --try again "<<endl;
} while (selection!='q'&& selection!='Q');
cout<<endl;
return 0;
}
【问题讨论】:
-
您可以使用逻辑与和逻辑或。请描述您遇到的问题。这段代码对我来说很好。
-
谷歌搜索布尔逻辑中的德摩根定律。
-
!A && !B == !(A || B)
-
@Swordfish 奇怪的是 OP 似乎理解德摩根定律,所以我不明白这个问题是关于什么的。
-
@john 我不确定他是否理解。
标签: c++