| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1244 人关注过本帖
标题:大家来看看这段程序错在哪里。
取消只看楼主 加入收藏
Tansion2010
Rank: 1
等 级:新手上路
帖 子:38
专家分:8
注 册:2010-4-24
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:2 
大家来看看这段程序错在哪里。
程序目的:输入百分制成绩,要求输入成绩登记'A'、'B'、'C'、'D'、'E'。90分以上为'A',80~89分为'B',70~79分为'C',60~69分为'D',60分一下为'E'。
#include<stdio.h>
void main()
{
    float mark;
    int mark1;
    scanf("%f",&mark);
    mark1=int(mark);
    switch(mark1)
    {
    case mark1>=90:printf('A');break;
    case mark1>=80 && mark1<=89:printf('B');break;
    case mark1>=70 && mark1<=79:printf('C');break;
    case mark1>=60 && mark1<=69:printf('D');break;
    default:printf('E');break;
    }
}
结果显示了错误:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
E:\C++临时文件\Cpp1.cpp(10) : error C2051: case expression not constant
E:\C++临时文件\Cpp1.cpp(10) : error C2664: 'printf' : cannot convert parameter 1 from 'const char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++临时文件\Cpp1.cpp(11) : error C2051: case expression not constant
E:\C++临时文件\Cpp1.cpp(11) : error C2664: 'printf' : cannot convert parameter 1 from 'const char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++临时文件\Cpp1.cpp(12) : error C2051: case expression not constant
E:\C++临时文件\Cpp1.cpp(12) : error C2664: 'printf' : cannot convert parameter 1 from 'const char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++临时文件\Cpp1.cpp(13) : error C2051: case expression not constant
E:\C++临时文件\Cpp1.cpp(13) : error C2664: 'printf' : cannot convert parameter 1 from 'const char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++临时文件\Cpp1.cpp(14) : error C2664: 'printf' : cannot convert parameter 1 from 'const char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\C++临时文件\Cpp1.cpp(15) : warning C4065: switch statement contains 'default' but no 'case' labels
Error executing cl.exe.

Cpp1.exe - 9 error(s), 1 warning(s)
搜索更多相关主题的帖子: 60分 90分 default include 
2010-05-10 18:39
Tansion2010
Rank: 1
等 级:新手上路
帖 子:38
专家分:8
注 册:2010-4-24
收藏
得分:0 
回复 6楼 yc2575757
只写“case 100:”就可以了吧?90分以上的都是“A”啊。
2010-05-11 08:36
Tansion2010
Rank: 1
等 级:新手上路
帖 子:38
专家分:8
注 册:2010-4-24
收藏
得分:0 
回复 7楼 childrush
严重同意你的最后一句话!谢谢你的鼓励!
2010-05-11 08:37
快速回复:大家来看看这段程序错在哪里。
数据加载中...
 
   



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

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