| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 694 人关注过本帖
标题:问一个关于枚举
取消只看楼主 加入收藏
树上月
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:114
专家分:154
注 册:2010-1-6
结帖率:87.5%
收藏
已结贴  问题点数:15 回复次数:1 
问一个关于枚举
最近看到这样一个关于水果拼盘的另解:
  现有苹果,橘子,香蕉,菠萝,梨5种水果用来做水果拼盘,每个水果拼盘一定有三个水果,且这3个水果的种类不同,问可以制作多少个水果拼盘:
   #include<stdio.h>
void main()
{
    enum fruit {apple,orange,banana,pineapple,pear};   //定义枚举结构
    enum fruit x,y,z,pri;                             //定义枚举变量
    int n=0,loop;
    for(x=apple;x<=pear;x++)
        for(y=apple;y<=pear;x++)
            if(x!=y){
                for(z=apple;z<=pear;z++)
                    if((z!=x)&&(z!=y)){
                        n=n+1;
                        printf("\n%-4d",n);
                        for(loop=1;loop<=3;loop++)
                        {
                            switch(loop){
                            case 1:
                                pri=x;
                                break;
                            case 2:
                                pri=y;
                                break;
                            case 3:
                                pri=z;
                                break;
                            default :break;
                            }
                            switch(pri){
                            case apple:
                                printf("%-9s","apple");
                                break;
                            case orange:
                                printf("%-9s","orange");
                                break;
                            case pineapple:
                                printf("%-9s","pineapple");
                                break;
                            case pear:
                                printf("%-9s","pear");
                                break;
                            default:break;
                            }
                        }
                    }
            }
}
   
复杂了点》但在Vc下运行有错误?该怎么改呢?
搜索更多相关主题的帖子: 枚举 
2010-03-18 22:47
树上月
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:114
专家分:154
注 册:2010-1-6
收藏
得分:0 
回复 3楼 mikelr
在VC下和我出现了一样的问题啊:
\users\lenovo\desktop\新建文件夹\fhjuyt.cpp(9) : error C2676: binary '++' : 'enum main::frui' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\users\lenovo\desktop\新建文件夹\fhjuyt.cpp(11) : error C2676: binary '++' : 'enum main::frui' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\users\lenovo\desktop\新建文件夹\fhjuyt.cpp(13) : error C2676: binary '++' : 'enum main::frui' does not define this operator or a conversion to a type acceptable to the predefined operato

每一个不曾起舞的日子,都是对未来的一种辜负......
2010-03-18 23:27
快速回复:问一个关于枚举
数据加载中...
 
   



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

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