为什么 do while 循环不会中断?
why does the do while loop doesn't break?
我在使用以下代码时遇到问题
switch(adminChoice){
case 1:
do{
cout<<"\nEnter Student ID: ";
cin>>studentId;
cout<<"\nEnter Student Name: ";
cin>>studentName;
cout<<"\nEnter Student Password: ";
cin>>studentPassword;
cout<<"\nAdd another account? y/n ";
cin>>adminSubChoice;
}
while(adminSubChoice!='n' || adminSubChoice !='N');
break;
case 2:
当我为 char
变量输入 n 或 N 时,do while
不会中断 adminSubChoice
它会一次又一次地保持 运行。有人可以告诉我我做错了什么吗??
条件 adminSubChoice!='n' || adminSubChoice !='N'
将始终为真,因为没有字符会同时为 n
和 N
。
条件应该是adminSubChoice!='n' && adminSubChoice !='N'
.
我在使用以下代码时遇到问题
switch(adminChoice){
case 1:
do{
cout<<"\nEnter Student ID: ";
cin>>studentId;
cout<<"\nEnter Student Name: ";
cin>>studentName;
cout<<"\nEnter Student Password: ";
cin>>studentPassword;
cout<<"\nAdd another account? y/n ";
cin>>adminSubChoice;
}
while(adminSubChoice!='n' || adminSubChoice !='N');
break;
case 2:
当我为 char
变量输入 n 或 N 时,do while
不会中断 adminSubChoice
它会一次又一次地保持 运行。有人可以告诉我我做错了什么吗??
条件 adminSubChoice!='n' || adminSubChoice !='N'
将始终为真,因为没有字符会同时为 n
和 N
。
条件应该是adminSubChoice!='n' && adminSubChoice !='N'
.