开发者

troubleshoot for "if" function

When compiling the following segment of code, I am receiving the err开发者_如何学Goor, "expected-primary expression before "int". Anyone have an idea what the problem is?

void letterGrade (int score)
{
     if (int score >= 90)
     {
             scoreLetter = 'A'
     }
     else if (int score >= 80)
     {
             scoreLetter = 'B'
     }
 }

Edit: Code Cleanup


remove "int" in the if statement, the variable is defined already


Remove the int keyword before score in if comparision.

void letterGrade (int score) {

if (score >= 90) { scoreLetter = 'A';}

else if (score >= 80) { scoreLetter = 'B';}

}


The reason you should remove the int from in front of score in the test statements is that with the int your code defines new local variables named score within that scope. Whereas you intend to use the score variable for the overall function scope, not just score defined within your if statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜