【发布时间】:2023-03-14 00:13:01
【问题描述】:
我正在为我的布尔表达式使用 switch case,答案是是或否。但如果答案无效,我希望它循环回来。我如何使用 if 或 while 循环与 Character 中的答案可以变化为 'y' 'Y' 'n' 'N'?下面的 if 语句可以工作吗?
if (mstatus != 'y', 'Y', 'N', 'n')
{
switch(mstatus)
case 'y':
printf("You have answer yes for married");
break;
case 'Y':
printf("You have answer yes for married");
break;
case 'n':
printf("You have answer no for married");
break;
case 'N':
printf("You have answer no for married");
break;
}
else
{
default:
printf("please re-enter a valid answer");
scanf(" %c", &mstatus);
}
return 0;
【问题讨论】:
-
请edit问题并正确缩进代码。
-
一个案例(双关语)用于贯穿开关案例逻辑(如果有的话)。
标签: c loops if-statement switch-statement