当前位置: 代码迷 >> C语言 >> 帮忙!一个菜鸟问题!!!!
  详细解决方案

帮忙!一个菜鸟问题!!!!

热度:167   发布时间:2008-04-06 21:01:45.0
帮忙!一个菜鸟问题!!!!
枚举的一道题:很简单
#include <stdio.h>
void main()
{
    enum color{red,yellow,blue,white,black};
    enum color i,j,k,pri;
    int n=0,loop;
    for(i=red;i<=black;i++)
    {
        for(j=red;j<=black;j++)
            if(i!=j)
            {
                for(k=red;k<=black;k++)
                    if(i!=k&&j!=k)
                    {
                        printf("%-4d",++n);
                        for(loop=1;loop<4;loop++)
                        {
                            switch(loop)
                            {
                            case 1:pri=i;break;
                            case 2:pri=j;break;
                            case 3:pri=k;break;
                            }
                        }
                        switch(pri)
                        {
                        case red:printf("%-8s","red");break;
                        case yellow:printf("%-8s","yellow");break;
                        case blue:printf("%-8s","blue");break;
                        case white:printf("%-8s","white");break;
                        case black:printf("%-8s","black");break;
                        }
                        putchar('\n');
                    }
            }
    }
}
错误是:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
g:\1\cpp1.cpp(7) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
g:\1\cpp1.cpp(9) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
g:\1\cpp1.cpp(12) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
执行 cl.exe 时出错.

Cpp1.obj - 1 error(s), 0 warning(s)
我用VC++6-0
----------------解决方案--------------------------------------------------------
enum color i,j,k,pri;
换int
----------------解决方案--------------------------------------------------------
enum color{red,yellow,blue,white,black};
    enum color i,j,k,pri;//更改为:  int i,j,k,pri;//不知道你定义color的意思
    int n=0,loop;

[[it] 本帖最后由 yunsuoyan 于 2008-4-6 21:26 编辑 [/it]]
----------------解决方案--------------------------------------------------------
  相关解决方案