大家来看看这段程序错在哪里。
程序目的:输入百分制成绩,要求输入成绩登记'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)