C程序SWITCH

来源:百度知道 编辑:UC知道 时间:2024/05/29 18:12:10
输入一个字符,如是“a”或“A”,输出“Abort”,如是“r”或“R”输出“Retry”,如是“f”或“F”,输出“Fail”。否则,给出出错信息。
要求:(1)用switch语句完成。
(2)调试程序并验证程序的正确性

switch(char)
{
case a:
case A:
printf("Abort");
case r:
case R:
printf("Retry");
case f:
case F:
printf("Fail");
default:
printf("error");
}

楼上的字符的引号没有加,break也没有加

switch(char)
{
case 'a':
case 'A':
printf("Abort"); break;
case 'r':
case 'R':
printf("Retry"); break;
case 'f':
case 'F':
printf("Fail"); break;
default:
printf("error");
}