我拥有的这个函数调用另一个不返回任何内容的函数,然后如果输入 q,while 语句应该允许退出函数。它不工作。当我输入 q 或 Q 时,它会打印谢谢,再见。然后就像未满足条件一样开始切换。有任何想法吗?
void Watch::userInteraction()
{
daysInMonthSwitch();
char answer;
while (answer != 'q' || answer != 'Q')
{
cout << "What would you like to do?" << endl;
cout << "Enter r to run." << endl;
cout << "Enter c to change time or date." << endl;
cout << "Enter q to quit." << endl;
cin >> answer;
switch(answer)
{
case 'r':
tick();
break;
case 'R':
tick();
break;
case 'c':
changeTimeOrDate();
break;
case 'C':
changeTimeOrDate();
break;
case 'q':
cout << "Thank you, goodbye";
break;
case 'Q':
cout << "Thank you, goodbye";
break;
default :
userInteraction();
}
}
}