Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It reads 3 test scores, calculates the percentage, and then outputs it into a le

ID: 3639861 • Letter: I

Question

It reads 3 test scores, calculates the percentage, and then outputs it into a letter grade. The Main should only call functions, and use at least 3 function calls.

I have written the code, and it works, but the result is wrong. Not sure what is wrong with my function, but here is the code:


void readScores(int* a, int* b, int*c);
int calcGrade(int score1, int score2, int score3);
char results(char fgrade);

int main(void)
{
int a;
int b;
int c;
char finalGrade;
int dummy;

// statements

readScores(&a, &b, &c);
finalGrade = calcGrade(a, b, c);
results(finalGrade);

printf("");
scanf("%d", &dummy);
return 0;

} // main

void readScores(int* a, int* b, int* c)
{
printf("Please enter the 3 grades: ");
scanf("%d %d %d", &a, &b, &c);

return;
}

int calcGrade(int score1, int score2, int score3)
{
int gAvg;
char finalGrade;

gAvg = (score1 + score2 + score3)/3;

if(gAvg >= 90)
finalGrade = 'A';
if(gAvg >= 80)
finalGrade = 'B';
if(gAvg >= 70)
finalGrade = 'C';
if(gAvg >= 50)
finalGrade = 'D';
if(gAvg >= 0)
finalGrade = 'F';

return finalGrade;
}

char results(char fGrade)
{
printf("The final grade is: %c ", fGrade);
return 0;

}

Explanation / Answer

// I have edited your program a bit so it works now


#include<stdio.h>


void readScores(int *a, int *b, int *c);

char calcGrade(int score1, int score2, int score3);

void results(char fgrade);

int main(void)

{

int a,b,c;

char finalGrade,dummy;

readScores(&a, &b, &c);

finalGrade = calcGrade(a, b, c);

results(finalGrade);
printf("");

scanf("%c", &dummy);

return 0;
}

// main
void readScores(int *a, int *b, int *c)

{

printf("Please enter the 3 Scores : ");

scanf("%d %d %d", a, b, c);

return;

}


char calcGrade(int score1, int score2, int score3)

{

float gAvg;

char finalGrade;
gAvg = (score1 + score2 + score3)/3.0;
if(gAvg >= 90)finalGrade = 'A';

else if(gAvg >= 80)finalGrade = 'B';

else if(gAvg >= 70)finalGrade = 'C';

else if(gAvg >= 50)finalGrade = 'D';

else if(gAvg >= 0)finalGrade = 'F';
return finalGrade;

}


void results(char fGrade)

{

printf("The final grade is: %c ", fGrade);

return ;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote