| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 357 人关注过本帖
标题:switch用对了吗?
只看楼主 加入收藏
onion555
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-9-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
switch用对了吗?
#include<stdio.h>
#define BASEERS 40
#define OVERTIMES 1.5
#define AMT1 300
#define AMT2 150
#define RATE1 0.15
#define RATE2 0.2
#define RATE3 0.25
int main()
{
    double sum,tax,net,hr,hours;
    int a;

    printf("enter the number corresponding to the desired pay rate or action:\n");
    printf("1)$8.75/hr         2)$9.33/hr\n");
    printf("3)$10.00/hr        4)$11.20/hr\n");
    printf("5)quit;\n");
    while((scanf("%d",&a))==1)
    {
        switch(a)
        {
            case '1':
                hr=8.75;
                break;
            case '2':
                hr=9.33;
                break;
            case '3':
                hr=10.00;
                break;
            case '4':
                hr=11.20;
                break;
            case '5':
                hr=0.0;
                break;
            default:
                hr=1.0;
        }
   
        if(hr==1.0)
        {
            printf("it's error,please enter a number from 1 to 5.\n");
            continue;
        }
        else if(hr==0.0)
            break;
        else
        {
            printf("please enter the number of hours worked this hours.\n");
            scanf("%f",&hours);
            if(hours<=BASEERS)
                sum=hours*hr;
            else
                sum=hr*BASEERS+hr*(hours-BASEERS)*OVERTIMES;
            if(sum<AMT1)
            {
                tax=sum*RATE1;
                net=sum-tax;
            }
            else if(sum<(AMT1+AMT2))
            {
                tax=AMT1*RATE1+(sum-AMT1)*RATE2;
                net=sum-tax;
            }
            else
            {
                tax=AMT1*RATE1+AMT2*RATE2+(sum-AMT1-AMT2)*RATE3;
                net=sum-tax;
            }
        }
        printf("sum is %.2f,tax is %.2f,net is %.2f.\n",sum,tax,net);
    }

    return 0;
}


为什么按1-5,会出来it's error,please enter a number from 1 to 5。想不通,跪求指导啊
搜索更多相关主题的帖子: desired include double number action 
2015-09-23 16:52
我爱吃青菜
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:6
帖 子:190
专家分:500
注 册:2015-3-29
收藏
得分:20 
case '1'改成case 1
用引号就是字符型的了
2015-09-23 16:55
onion555
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-9-13
收藏
得分:0 
回复 2楼 我爱吃青菜
嗯,对了。谢谢哈
2015-09-23 17:02
快速回复:switch用对了吗?
数据加载中...
 
   



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

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