| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 824 人关注过本帖
标题:求助!while中的switch问题,望解惑。
取消只看楼主 加入收藏
wbing915
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2009-11-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求助!while中的switch问题,望解惑。
这是我编的题目其中的一段
 #include <stdio.h>
int main(void)
{
    char kind;
    int mark=0;
    float a_pounds,b_pounds,c_pounds,allpounds,total,o_cost,pl_price;

    a_pounds=b_pounds=c_pounds=allpounds=pl_price=0;
    printf("Choose the vagetable you want to buy:\n");
    printf("a.artichoke.          b.beet.\n");
    printf("c.carrot.             q.quit.\n");
    while(scanf("%c",&kind))
    {
        switch(kind)
        {
    case'a':printf("Enter the pounds:\n");
             scanf("%f",&a_pounds);
             break;
    case'b':printf("Enter the pounds:\n");
             scanf("%f",&b_pounds);
            break;
    case'c':printf("Enter the pounds:\n");
             scanf("%f",&c_pounds);
            break;
    case'q':mark=1;
             break;
        }
        if(mark)
            break;
        printf("Choose another vagetable:\n");
    }
执行时为什么“Choose another vagetable:”这句话会输出两遍呢?实在不懂。
麻烦知道的解释一下,万分感谢!
搜索更多相关主题的帖子: total total 问题 问题 include include Enter Enter 
2011-09-16 10:19
wbing915
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2009-11-17
收藏
得分:0 
后来想通了,主要是回车键算了一次字符,所以多循环了一次,谢谢各位了。
2011-09-16 13:06
快速回复:求助!while中的switch问题,望解惑。
数据加载中...
 
   



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

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