| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 653 人关注过本帖
标题:关于C选择结构(switch)
只看楼主 加入收藏
maoxiaojian
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-9-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:10 
关于C选择结构(switch)
请高手帮忙看一下下面的程序哪里错了:
#include<stdio.h>
int main()
{
float score;
char grade;
printf("please printf your score:");
scanf("%f",&score);
while(score>100||score<0)
{
printf("\nprintf is wrong,please printf again");
scanf("%f",&score);
}
switch((int)(score/10))
{
case10:
case9:grade='A';break;
case8:grade='B';break;
case7:grade='C';break;
case6:grade='D';break;
case5:
case4:
case3:
case2:
case1:
case0:grade='E';
}
printf("the score is %5.1f,the grade is %c\n",score,grade);
return 0;
}
(不考虑英语语法错误)
输入56
运行结果是:
the score is 56.0,the grade is
也就是说运行结果没有输出等级,怎么回事呢?



搜索更多相关主题的帖子: return please include 结构 
2012-09-09 21:35
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:3 
程序代码:
#include<stdio.h>

int main()
{
    float score;
    char grade;
    printf("please printf your score:");
    scanf("%f",&score);
    while(score>100||score<0)
    {
        printf("\nprintf is wrong,please printf again");
        scanf("%f",&score);
    }
    switch((int)(score/10))
    {
    case 10:
    case 9:grade='A';break;
    case 8:grade='B';break;
    case 7:grade='C';break;
    case 6:grade='D';break;
    case 5:
    case 4:
    case 3:
    case 2:
    case 1:
    case 0:grade='E';
    }
    printf("the score is %5.1f,the grade is %c\n",score,grade);
    return 0;
}


我怀疑你帖的那个能不能编译通过 你编译通过了?
2012-09-09 21:46
qq520520
Rank: 1
等 级:新手上路
帖 子:3
专家分:3
注 册:2012-9-9
收藏
得分:3 
表示只把“:”改成正确的后,一直有E
2012-09-09 21:48
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
please printf your score:56
the score is  56.0,the grade is E

please printf your score:99
the score is  99.0,the grade is A

please printf your score:89
the score is  89.0,the grade is B

please printf your score:20
the score is  20.0,the grade is E

上面的那个 运行结果是这样的
2012-09-09 21:52
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

认真看 这个冒号和其他的有啥不同
2012-09-09 21:53
w995612220
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:139
专家分:313
注 册:2012-6-20
收藏
得分:3 
case 0:空格自己吃了.基础很差.
2012-09-09 23:30
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:3 
这个有点无语……
2012-09-09 23:46
QQ007977
Rank: 2
等 级:论坛游民
帖 子:29
专家分:43
注 册:2012-9-9
收藏
得分:3 
#include<stdlib.h>

#include<stdio.h>
int main()
{
float score;
char grade;
printf("please printf your score:");
scanf("%f",&score);
while(score>100||score<0)
{
printf("\nprintf is wrong,please printf again");
scanf("%f",&score);
}
switch((int)(score/10))
{
case10:
case9:grade='A';break;
case8:grade='B';break;
case7:grade='C';break;
case6:grade='D';break;
default:grade='E';
}
printf("the score is %5.1f,the grade is %c\n",score,grade);
    system("pause");
}


稍微改了一下你的代码
2012-09-10 10:06
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:3 
我一直都犯小错误,这个需要细心啊,楼主。一定要细心啊,很多问题不是只是问题,是认真度啊,还有汗水。

我只是个演员,还是业余的!!
2012-09-11 00:07
经哥
Rank: 3Rank: 3
来 自:代码空间
等 级:论坛游侠
威 望:1
帖 子:289
专家分:124
注 册:2012-9-8
收藏
得分:0 
回复 5楼 zklhp
我想问问啊,只是问问,不是怀疑,你是怎么发现他的错误点在冒号那里的?新手真心不懂啊

我只是个演员,还是业余的!!
2012-09-11 00:11
快速回复:关于C选择结构(switch)
数据加载中...
 
   



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

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