#include <stdio.h>
void main()
{
printf("please enter the first letter of someday:\n");
char letter;
while((letter=getchar())!='y')
{switch(letter){
case 'S':
{printf("please enter the second letter:");
if((letter=getchar())=='a')
printf("It is Saturday!\n");
else if((letter=getchar())=='u')
printf("It is Sunday!\n");
else printf("error\n");
break;
}
case 'M':printf("It is Monday!\n");
break;
case 'T':{
printf("please enter the second letter:");
if((letter=getchar())=='h')
printf("It is Tuesday!\n");
else if((letter=getchar())=='u')
printf("It is Thursday!\n");
break;
}
case 'F':printf("It is Friday!\n");
break;
case 'W':printf("It is Wednesday!\n");
break;
}
}
}
现在遇到问题,比如说输入“S”,提示输入第二个字母,如果输入“u”,就输出Sunday,但如果输入“a”,就没有任何反应。
#include <stdio.h>
void main()
{
printf("please enter the first letter of someday:\n");
char letter;
while ((letter = getchar()) != 'y') {
switch (letter) {
case 'S': {
printf("please enter the second letter:");
getchar();
if ((letter = getchar()) == 'a') {
printf("It is Saturday!\n");
} else if (letter == 'u') {
printf("It is Sunday!\n");
} else {
printf("error\n");
}
break;
}
case 'M':
printf("It is Monday!\n");
break;
case 'T': {
printf("please enter the second letter:");
getchar();
if ((letter = getchar()) == 'h') {
printf("It is Tuesday!\n");
} else if (letter == 'u') {
printf("It is Thursday!\n");
}
break;
}
case 'F':
printf("It is Friday!\n");
break;
case 'W':
printf("It is Wednesday!\n");
break;
}
}
}
default:
break;
这里你没加默认的