C programming Determine Students grade
-
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations.
#include <stdio.h>
// Function Declarations
int main (void)
{
// Local Declarations
int score1, score2, score3;
char grade;
int temp = 0;// Statements
printf("Enter the test score (0-100): ");
scanf ("%d", &score1);
printf("Enter the test score (0-100): ");
scanf ("%d", &score2);
printf("Enter the test score (0-100): ");
scanf ("%d", &score3);printf("The grade is: %c\\n", score1, score2, score3); return 0;
} // main
/* =================== scoreToGrade ===================
This function calculates letter grade for a score.
Pre the parameter score
Post returns the grade
*/// Local Declarations
int temp = 0;
{
temp = (score1+score2+score3)/3;// Statements
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C';
else
if (score >= 60)
grade = 'D';
else
grade = 'F';char grade;
// Statements
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C'; -
Write a program that determines a student's grade. It reads three test scores(between 0 and 100) and calls a function that calculates and returns a student's grade based on the following rules: A. If the average score is 90% or more, the grade is A. B. If the average score is 70% or more and less than 90%, it checks the third score. If the third score is more than 90%, the grade is A; otherwise, the grade is B. and it continues... The program's main is to contain only call statements. At least three subfunctions are required: one to read scores, one to determine the grade, and one to print the results. This is what I have so far but it will not run for me. I am not allowed to use global declarations.
#include <stdio.h>
// Function Declarations
int main (void)
{
// Local Declarations
int score1, score2, score3;
char grade;
int temp = 0;// Statements
printf("Enter the test score (0-100): ");
scanf ("%d", &score1);
printf("Enter the test score (0-100): ");
scanf ("%d", &score2);
printf("Enter the test score (0-100): ");
scanf ("%d", &score3);printf("The grade is: %c\\n", score1, score2, score3); return 0;
} // main
/* =================== scoreToGrade ===================
This function calculates letter grade for a score.
Pre the parameter score
Post returns the grade
*/// Local Declarations
int temp = 0;
{
temp = (score1+score2+score3)/3;// Statements
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C';
else
if (score >= 60)
grade = 'D';
else
grade = 'F';char grade;
// Statements
if (score >= 90)
grade = 'A';
else
if (score >= 80)
grade = 'B';
else
if (score >= 70)
grade = 'C';You need to hit the books or web lessons on C again. Your 3 statement inputs look good ... sorry that is it :-) Your printf statement is garbage hit the web or books and look up the words "formatted output of printf" and look at what %c means. However you have done absolutely nothing with the inputs to even think about calling that. What we are saying is you need to call a function between the last input and trying to print anything ... so
scanf ("%d", &score3);
//... You need a function call in here to do something with the scores and then fix the print below
printf("The grade is: %c\n", score1, score2, score3);
You even have the text that boldly says "// Function declarations" only you don't have anything there you just drop straight into main. Let me guess that was a hint in the template they gave you and you don't even get what it means? ScoreToGrade which was obviously was intended as your function is hanging out way down the bottom. You need to either forward declare it where you boldly declare you are going to have "// Function declatations" or move it up to there. So it's a cut and paste job or look up how to forward declare a prototype. Final problem
// Local Declarations
int temp = 0;It says it is local it is in fact a global variable ... you need to work out why.
In vino veritas