Here is my code:
//preprocessor files
#include <stdio.h>
#include <stdlib.h>
void printScores(float scores[]);
int main()
{
char s_name[] = "ECPI University";
float scores[6] = {78.7, 98.4, 100.0, 96.5, 100.0,
88.8};
float average = 0.0;
int counter;
printScores(scores);
for(counter = 0; counter < 6; counter++){
average += scores[counter];
}
average /= float(6); ===============this is where i am
getting the error
printf("\nAt %s, your class average is %.1f.", s_name,
average);
system("pause");
return 0;
}
void printScores(float scores[6]){
int counter;
printf("Here are your scores:\n\n");
for(counter =0; counter < 6; counter++){
printf("%.1f\n,",
scores[counter]);
}
return;
}
Why am I getting this error: [Error] expected expression before 'float' for the code portion above i have commented to the right of?
//preprocessor files #include <stdio.h> #include <stdlib.h> void printScores(float scores[]); int main() { char s_name[] = "ECPI University"; float scores[6] = {78.7, 98.4, 100.0, 96.5, 100.0, 88.8}; float average = 0.0; int counter; printScores(scores); for(counter = 0; counter < 6; counter++){ average += scores[counter]; } average /= 6.0; printf("\nAt %s, your class average is %.1f.", s_name, average); system("pause"); return 0; } void printScores(float scores[6]){ int counter; printf("Here are your scores:\n\n"); for(counter =0; counter < 6; counter++){ printf("%.1f\n,", scores[counter]); } return; } Note: float value for 6 is 6.0 So, You can directly use 6.0 If you still want to use float keyword then use below statement average /= (float)6;
Get Answers For Free
Most questions answered within 1 hours.