csfl0 csfl0 - 15 days ago 5
C++ Question

Expected A Declaration CPP

little problem and I can't get to the bottom of it. The { at line 35 expected a declaration. I can't for the life of me fix it. Here's all of the code together, I have commented in the code next to the { for where the problem is arising.

#include <stdio.h>
char ScoreMarks(float percentage);
char ScoreRawMarks(float scoreAwarded, float mscoreAvailable);

int main(void)
{
float percent, Awarded, Available;
char result;
printf("Enter Score Available\n");
scanf("%f", &Available);
printf("Enter Score Awarded\n");
scanf("%f", Awarded);
result = ScoreFromRawMarks(Awarded, Available);
printf("Score Achieved = %c\n", result);
}
char ScoreFromPercentage(float percentage)
{
char output;
if (percentage >= 90.0) {
output = 'A';
}
else if (percentage >= 70.0) {
output = 'B';
}
else if (percentage >= 50.0) {
output = 'c';
}
else if (percentage >= 30.0) {
output = 'D';
}
else {
output = 'F';
}
return output;
};
char ScoreFromRawMarks(float scoreAwarded, float scoreAvailable, float percentage);
{ //EXPECTED DECLARATION
char output;
percentage = (scoreAwarded / scoreAvailable) * 100;
output = ScoreFromPercentage(scoreAwarded, scoreAvailable);
return output;
}

Answer

You have a semicolon at the end of this line which makes the compiler think you're doing a function prototype:

char ScoreFromRawMarks(float scoreAwarded, float scoreAvailable, float percentage);
{ //EXPECTED DECLARATION