问题描述
- c枚举运算有问题请教各位geek
-
#include"stdio.h"
typedef enum {Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}weekday;
weekday previousday(weekday nowaday);
weekday nextday(weekday nowaday);
int main()
{
int choise;
weekday nowaday,theday;
printf("please input nowaday");
scanf("%c",&nowaday);
printf("please input your choise,0:priviousday 1:nextday");
scanf("%d",&choise);
choise==0?theday=previousday(nowaday):theday=nextday(nowaday);
printf("%c",theday);
}weekday previousday(weekday nowaday)
{
nowaday=(weekday)(nowaday+1);
return (weekday)(nowaday%7);
}
weekday nextday(weekday nowaday)
{
nowaday=(weekday)(nowaday-1);
return (weekday)(nowaday%7);
}
请帮忙看看这个问题出在哪儿了?谢了。
解决方案
#include "stdafx.h"
#include"stdio.h"
typedef enum {Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}weekday;
weekday previousday(weekday nowaday);
weekday nextday(weekday nowaday);
int main()
{
int choise;
weekday nowaday,theday;
printf("please input nowaday");
scanf("%d",&nowaday);
printf("please input your choise,0:priviousday 1:nextday");
scanf("%d",&choise);
//choise==0?theday=previousday(nowaday):theday=nextday(nowaday);
theday=choise==0?previousday(nowaday):nextday(nowaday);
printf("%d",theday);
}
weekday previousday(weekday nowaday)
{
nowaday=(weekday)(nowaday-1);
return (weekday)(nowaday%7);
}
weekday nextday(weekday nowaday)
{
nowaday=(weekday)(nowaday+1);
return (weekday)(nowaday%7);
}
试试,看看哪里不明白?