初用枚举型

来源:互联网 发布:知乎日报与知乎 编辑:程序博客网 时间:2024/04/30 13:15

#include  <iostream.h> 
enum WEEKDAY 

sun,mon,tue,wed,thu,fri,sat 
}; 
WEEKDAY nextDayof(WEEKDAY today) 
{
 if(today <7){
  if (today==sat) 
  { 
   return sun; 
  } 
  return static_cast <WEEKDAY>(today+1);
 }
 else{
  cout<<"input error" <<endl;
  return static_cast <WEEKDAY>(-1);
 }
 

void main() 
{
 
 int today, nextday;
 cout  <<"input today:"; 
 cin>>today;
 nextday=nextDayof(static_cast <WEEKDAY>(today));
 switch(nextday){
 case 0:
  cout<<"the next day is :"  <<"sun" <<endl;
  break;
 case 1:
  cout  <<"the next day is :"  <<"mon" <<endl;
  break;
 case 2:
  cout  <<"the next day is :"  <<"tue" <<endl;
  break;
 case 3:
  cout  <<"the next day is :"  <<"wed"  <<endl;
  break;
 case 4:
  cout  <<"the next day is :"  <<"thu" <<endl;
  break;
 case 5:
  cout  <<"the next day is :"  <<"fri" <<endl;
  break;
 case 6:
  cout  <<"the next day is :"  <<"sat" <<endl;
  break;
 }