C语言枚举实例出现问题!

来源:百度知道 编辑:UC知道 时间:2024/05/22 20:41:49
#include <stdio.h>
main()
{
int i,k;
enum year{JAN=1,FEB,MAR,APR,AUG,SEP,OCT,NOV,DEC}month[9],j;
printf("\nPlease Input The Month:");
scanf("%d",&i);
j=JAN;
for(k=1;k<=9;k++)
{
month[k]=j;
j++;
}
switch(month[i])
{
case JAN:printf("This is JAN Month.");break;
case FEB:printf("This is FEB Month.");break;
case MAR:printf("This is MAR Month.");break;
case APR:printf("This is APR Month.");break;
case AUG:printf("This is AUG Month.");break;
case SEP:printf("This is SEP Month.");break;
case OCT:printf("This is OCT Month.");break;
case NOV:printf("This is NOV Month.");break;
case DEC:printf("This is DEC Month.");break;
default:printf("Input error!");break;
}

我输入12
输出
Please Input The Month:12
Input error!
正确啊。不知你在什么编译器下运行啊!我在win-TC下正常。

#include <stdio.h>
main()
{
int i,k;
enum year{JAN=1,FEB,MAR,APR,AUG,SEP,OCT,NOV,DEC}month[9],j;
printf("\nPlease Input The Month:");
scanf("%d",&i);
j=JAN;
for(k=1;k<=9;k++)
{
month[k]=j;
j++;
}
switch(i)
{
case JAN:printf("This is JAN Month.");break;
case FEB:printf("This is FEB Month.");break;
case MAR:printf("This is MAR Month.");break;
case APR:printf("This is APR Month.");break;
case AUG:printf("This is AUG Month.");break;
case SEP:printf("This is SEP Month.");break;
case OCT:printf("This is OCT Month.");break;
case NOV:printf("This is NOV Month.");break;
case DEC:printf("This is DEC Month.");break;
default: