You are here:

C/C Programming

Advertisement


Question
I need to 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:

THIS IN C NOT C++

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.

c. If the average score is 50% or more and less than 70%, it checks the average of the second and third scores. If the average of the two is greater than 70%, the grade is C; otherwise, it is D.

d. If the average score is less than 50% percent, then the grade is F.

The program’s main is to contain only call statements. At least three sub-functions are required: one to determine the grade, and one to print the results.

THIS IS WHAT I HAVE SO FAR BUT IM STUCK HELP!!



#include <stdio.h>

// Function Declarations
char scoreToGrade (int score1, int score2, int score3);

int main (void)
{
// Local Declarations
int score1, score2, score3;
char grade;

// 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);

grade = scoreToGrade (score1, score2, score3);
printf("The grade is: %c\n", grade);

return 0;
} // main
/* ==================== scoreToGrade ===================
This function calculates the letter grade for a score.
Pre the parameter score
Post returns the grade
*/
char scoreToGrade (int score1, int score2, int score3)
{

temp = (score1+score2+score3)/ 3;
//here just use simple if else if statements
if(temp>=90){
grade = 'A';
}
else if(temp<90 || temp>=70){
if(score3>90)
grade = 'A'
else if
grade = 'B'
}
38  

Answer
Hi Dear Mike !

Sorry for the delay in responding you , just got little busy ...

fine , please find the solution below. I haven't tested it well , please ensure that the following program meets all your cases , feel free to modify the code the way you wish!

Let me know in case of issue or you require additional explanation with the following code

#include<stdio.h>

// Function Declarations
char scoreToGrade (int score1, int score2, int score3);

int main (void)
{
// Local Declarations
  float score1, score2, score3;
  char grade;

// Statements
  printf("Enter the test score (0-100): ");
  scanf ("%f", &score1);
  printf("Enter the test score (0-100): ");
  scanf ("%f", &score2);
  printf("Enter the test score (0-100): ");
  scanf ("%f", &score3);

    
  printf("The grade is: %c\n", scoreToGrade (score1, score2, score3));
  getch();
  return 0;
} // main

/* ==================== scoreToGrade ===================
This function calculates the letter grade for a score.
Pre the parameter score
Post returns the grade
*/
char scoreToGrade (float score1, float score2, float score3)
{
  char grade;
  float temp = 0;
  temp = (score1+score2+score3)/ 3.0;
  //here just use simple if else if statements
  if(temp>=90)
  {
     grade = 'A';
  }
  else if(temp<90.0 && temp>=70.0)
  {
     if(score3>90.0)
        grade = 'A';
     else
        grade = 'B';
  }
  else if( temp > 50.0 && temp <=70.0)
  {
     if( ((score2+score3)/2.0) > 70.0)
        grade = 'C';
     else
        grade='E';

  }
  else if(temp < 50.0)
     grade = 'F';

  return grade;
}


Thanks and Regards
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.