题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,
则继续判断第二个字母。
#include <iostream>
using namespace std;
//getchar 以^z来结束输入(Ctrl + z)
void main()
{
char c;
cout<<"Please enter a char:"<<endl;
while(c=getchar())
{
switch(c)
{
case 'm':
cout<<"It's monday."<<endl;
;break;
case 't':
{
cout<<"Enter again."<<endl;
bool flag = false;
while(c=getchar())
{
switch(c)
{
case 'u':
cout<<"It's tuesday."<<endl;break;
case 'h':
cout<<"It's thursday."<<endl;break;
default:
cout<<"Enter once again."; flag = true;break;
}
if(flag)
break;
}
}
;break;
case 'w':
cout<<"It's wednesday."<<endl;
;break;
case 'f':
cout<<"It's friday."<<endl;
;break;
case 's':
{
cout<<"Enter again."<<endl;
bool flag = false;
char d;
while(d=getchar())
{
switch(d)
{
case 'a':
cout<<"It's saturday."<<endl;break;
case 'u':
cout<<"It's sunday."<<endl;break;
default:
cout<<"Enter once again."<<endl; flag = true;break;
}
if(flag)
break;
}
}
;break;
default:
cout<<"Please enter a char again!"<<endl;
;break;
}
}
}