问题描述
嘿,伙计们再次对我说,在课堂上遇到麻烦。我们写了一个程序来测试成绩,答案密钥和学生在同一个文件中回答
我们必须阅读它们并对测试进行评分并且
然后分配一个等级并将所有这些输出到另一个文件。我已经完成了所有工作,但是根据分数不能得到分配
等级的开关结构。这是我得到的错误:
错误C2440:''='':无法从''const char [2]''转换为''char''
,这是该功能的来源:
char examGrades(int& score)
{
char ch2;
开关(static_cast< int>(得分/40.0 * 10))
{
案例0:案例1 :案例2:案例3:案例4:案例5:ch2 =" F" ;;
案例6:ch2 =" D" ;;
案例7:ch2 =" C";
case 8:ch2 =" B";
case 9:case 10:ch2 =" A";
默认:ch2 =" F" ;;
休息;
}
返回ch2;
}
任何建议都会很棒,因为今晚是午夜到期。我知道,我是一个可怕的拖延者! :(
再次感谢,
马特
Hey guys its me again, having trouble with a project for class. We''re
writing a program to Grade a test, the answer key and student answers r
in the same file and we have to read them in and score the test and
then assign a grade and output all of that to another file. I''ve got
everything done, just can''t get the switch structure that assigns the
grades based on the score to work. This is the error I get :
error C2440: ''='' : cannot convert from ''const char [2]'' to ''char''
and this is the source for the function:
char examGrades(int& score)
{
char ch2;
switch(static_cast<int>(score /40.0 * 10))
{
case 0: case 1: case 2: case 3: case 4: case 5: ch2 = "F";
case 6: ch2 = "D";
case 7: ch2 = "C";
case 8: ch2 = "B";
case 9: case 10: ch2 = "A";
default: ch2 = "F";
break;
}
return ch2;
}
Any suggestions would be great as this is due by midnight tonight. I
know, I''m a horrible procrastinator! :(
Thanks Again,
Matt
推荐答案
你的问题是你应该使用双引号("),你应该
使用单引号('')。
-
小睡一下,它可以挽救生命。
Your problem is that you are using double quotes (") when you should
have used single quotes ('').
--
http://www.munted.org.uk
Take a nap, it saves lives.
FWIW你的函数中有更多错误(实际上是同一个重复)
这会导致它无法按预期运行。阅读关于开关
的声明,以发现你有什么错误。我也会查询
当一个好主意通过参考传递参数,const参考
或按价值
问候
Andy Little
FWIW there are more errors(actually same one repeated) in your function
which will cause it not to function as you expect. Read up about switch
statement to discover what you have dong wrong. I would also look up
when it is a good idea passing arguments by reference, const reference
or by value
regards
Andy Little
这篇关于项目难度大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!