| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 432 人关注过本帖
标题:[求助]switch的问题
只看楼主 加入收藏
nick7281
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2006-11-13
收藏
 问题点数:0 回复次数:2 
[求助]switch的问题
要求是在 I<= 100000时,i=I*0.1,100000< I <= 200000时,i = 100000 * 0.1 + (I - 100000) * 0.075,200000< I <= 400000时,i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05,400000< I <= 600000时,i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03,600000<I <= 1000000时,i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015,用switch语句来做。
我做这个有问题,如果大家有更好的办法,或者能改正这个都行,谢谢了

#include<stdio.h>
void main()
{
int I, x;
float i;
printf("Please enter the profit: \n");
scanf("%d", &I);
x = I/100000;
switch(x)
{
case'0': printf("The praise of the year is %f\n", i = I * 0.1);
break;
case'1': printf("The praise of the year is %f\n", i = 100000 * 0.1 + (I - 100000) * 0.075);
break;
case'2': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05);
break;
case'3': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05);
break;
case'4': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03);
break;
case'5': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03);
break;
case'6': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'7': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'8': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'9': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
case'10': printf("The praise of the year is %f\n", i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015);
break;
}
}
搜索更多相关主题的帖子: switch 
2007-02-04 11:50
davidloves
Rank: 1
等 级:新手上路
帖 子:137
专家分:0
注 册:2007-1-6
收藏
得分:0 
case 0 不是case '0'
后者表示的是0的ASCII码,好象是48

2007-02-04 12:11
nick7281
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2006-11-13
收藏
得分:0 
恩,我弄错了,现在改成这样的,应该要简洁得多。
#include<stdio.h>
void main()
{
int I, x;
float i;
printf("Please enter the profit: \n");
scanf("%d", &I);
x = (I - 1)/100000;
switch(x)
{
case 0: i = I * 0.1;
break;
case 1: i = 100000 * 0.1 + (I - 100000) * 0.075;
break;
case 2:
case 3: i = 100000 * 0.1 + 100000 * 0.075 + (I - 200000) * 0.05;
break;
case 4:
case 5: i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + (I - 400000) * 0.03;
break;
case 6:
case 7:
case 8:
case 9: i = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.05 + 200000 * 0.03 + (I - 600000)*0.015;
break;
}
printf("The praise of the year is %f\n", i);
}

[此贴子已经被作者于2007-2-4 12:29:57编辑过]


2007-02-04 12:18
快速回复:[求助]switch的问题
数据加载中...
 
   



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

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