今天是星期输出明天星期几,枚举类型的c++程序
发布网友
发布时间:2022-06-05 16:23
我来回答
共2个回答
热心网友
时间:2023-11-25 03:15
不知道楼主是不是要这样的效果:
#include<iostream.h>
char week[][7] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
enum WEEKDAY
{
sun,
mon,
tue,
wed,
thu,
fri,
sat
};
char *nextdayof(enum WEEKDAY today)
{
if(today==sat)
{
return week[sun];
}
return week[(enum WEEKDAY)((int)today+1)];
}
void main()
{
enum WEEKDAY today = wed;
cout << "今天是星期三" << endl;
cout << "明天是" << nextdayof(today) << endl;
}
热心网友
时间:2023-11-25 03:15
#include<iostream.h>
enum WEEKDAY{sun,mon,tue,wed,thu,fri,sat};
enum WEEKDAY nextdayof( enum WEEKDAY today){
if(today==sat) return sun;
return (enum WEEKDAY)((int)today+1);
}
void main()
{
enum WEEKDAY d, today=wed;
cout<<"今天是星期三";
cout<<"明天是"<<nextdayof(today);
}