项目难度大 [英] Difficulty with project

查看:95
本文介绍了项目难度大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们再次对我说,在课堂上遇到麻烦。我们写了一个程序来测试成绩,答案密钥和学生在同一个文件中回答
我们必须阅读它们并对测试进行评分并且

然后分配一个等级并将所有这些输出到另一个文件。我已经完成了所有工作,但是根据分数不能得到分配

等级的开关结构。这是我得到的错误:

错误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

推荐答案

没关系,我想出了问题。无论如何,谢谢!

Nevermind, I figured the problem out. Thanks anyway!


2006年4月25日18:49:09 -0700" ni ***** *****@yahoo.com"

< ni ********** @ yahoo.com>挥霍一根魔杖和这条消息神奇地说

出现:
On 25 Apr 2006 18:49:09 -0700 "ni**********@yahoo.com"
<ni**********@yahoo.com> waved a wand and this message magically
appeared:
case 0:case 1:case 2:case 3:case 4:case 5:ch2 =
" F" case 6:ch2 =" ; D;
情况7:ch2 =C;
情况8:ch2 =B;
情况9:情况10:ch2 =A;
默认:ch2 =" F";
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";




你的问题是你应该使用双引号("),你应该

使用单引号('')。


-
http://www.munted.org.uk

小睡一下,它可以挽救生命。



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.


ni ********** @ yahoo.com 写道:
嘿,伙计们再次给我,因为课堂上的项目有问题。我们正在编写一个程序来评分测试,答案键和学生在同一个文件中回答,我们必须阅读它们并对测试进行评分,然后分配一个等级并将所有这些输出到另一个文件。我已经完成了所有工作,根本无法获得根据分数分配
成绩的开关结构。这是我得到的错误:
错误C2440:''='':无法从''const char [2]''转换为''char''

这是功能来源:

char examGrades(int& score)
{ch ch2;

开关(static_cast< int>(得分/40.0) * 10))
{案例0:案例1:案例2:案例3:案例4:案例5:ch2 =" F" ;;
案例6:ch2 =" D" ;案例7:ch2 =C;
案例8:ch2 =B;
案例9:案例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;

}



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


这篇关于项目难度大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆