标题:请高手帮忙指点一下枚举类型的C程序,谢谢……
取消只看楼主
莫一阳
Rank: 1
等 级:新手上路
帖 子:38
专家分:6
注 册:2011-4-27
结帖率:78.57%
已结贴  问题点数:15 回复次数:2 
请高手帮忙指点一下枚举类型的C程序,谢谢……
/*枚举类型实例:口袋中有红,黄,蓝,白,黑5种颜色的球若干个。每次从口袋中先后
取出3个球,问得到3种不同色的球的可能取法,输出每种排列的情况*/
#include<stdio.h>

int main()
{
    enum color{red,yellow,blue,white,black};
    enum color i,j,k,pri;
    int n,loop;
    n=0;
    for(i=red;i<=black;i++)
    {
        for(j=red;j<=black;j++)
        {
            if(i!=j)
            {
                for(k=red;k<=black;k++)
                {
                    if((k!=i)&&(k!=j))
                    {
                        n=n+1;
                        printf("%-4d",n);
                        for(loop=1;loop<=3;loop++)
                        {
                            switch(loop)
                            {
                                case 1: pri=i;break;
                                case 2: pri=j;break;
                                case 3: pri=k;break;
                                default:break;
                            }
                            switch(pri)
                            {
                                case red:    printf("%-10s","red");break;
                                case yellow: printf("%-10s","yellow");break;
                                case blue:   printf("%-10s","blue");break;
                                case white:  printf("%-10s","white");break;
                                case black:  printf("%-10s","black");break;
                                default:break;
                            }
                        }
                        printf("\n");
                    }
                }
            }
        }
    }
    printf("\ntotal:%5d\n",n);   
}

编译出错:
--------------------Configuration: meiju - Win32 Debug--------------------
Compiling...
11.cpp
c:\myprojects\meiju\11.cpp(11) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\myprojects\meiju\11.cpp(13) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\myprojects\meiju\11.cpp(17) : error C2676: binary '++' : 'enum main::color' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\myprojects\meiju\11.cpp(49) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

11.obj - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: yellow blue 
2011-06-01 14:56
莫一阳
Rank: 1
等 级:新手上路
帖 子:38
专家分:6
注 册:2011-4-27
得分:0 
回复 2楼 木头lbj
我用C-free和VC6.0都试了,都不好使……
2011-06-03 15:51
莫一阳
Rank: 1
等 级:新手上路
帖 子:38
专家分:6
注 册:2011-4-27
得分:0 
回复 2楼 木头lbj
我刚用C-free又试了一下,好使,编译通过了……谢谢你……
你知道VC6.0为啥编译出错吗?
2011-06-03 16:01



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341627-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.665203 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved