我正在尝试接受用户的输入并检查它是否等于某个选项('+',' - ','*','x')
do {
printf("Select the op.: ");
scanf("%c", &option);
} while (option != '+' || option != '-' || option != '*' || option != 'x');
printf("%c", option);
Run Code Online (Sandbox Code Playgroud)
这是输出:
Select the op.:Select the op.:Select the op.:Select the op.:
Run Code Online (Sandbox Code Playgroud)
正如您所看到的那样,printf("Select the op.: ")多次执行并且我无法理解原因,因此如果我尝试插入,例如+,这是打印输出:
++
Run Code Online (Sandbox Code Playgroud)
提前致谢
Lig*_*ica 11
while(option != '+' || option != '-' || option != '*' || option != 'x');
Run Code Online (Sandbox Code Playgroud)
这种情况总是如此.