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.
精彩评论