switch()语句小问题
#include<iostream>
using namespace std;
int main()
{
char letter;
while(cin>>letter&&letter!='Z')
switch(letter)
{
case'S':cout<<"intput the second letter:\n";
if(cin>>letter&&letter=='u')
cout<<"Sunday";
else if(cin>>letter&&letter=='a')
cout<<"Saturday";
else
cout<<"error";
break;
case'T':cout<<"intput the second letter:\n";
if(cin>>letter&&letter=='h')
cout<<"Thusday";
else if(cin>>letter&&letter=='u')
cout<<"Tuesday";
else
cout<<"error";
break;
case'M':cout<<"Monday";break;
case'W':cout<<"Wesday";break;
case'F':cout<<"Friday";break;
}
return 0;
}
不知道程序那里错了,Saturday要输入两次a才能输出Saturday
请高手指点
参考答案:else if(cin>>letter&&letter=='a')
这里改成else if(letter=='a')
否则就等于要做两次cin了