You are here:

# C++/Function & Average

Question
I want to write a program that determine a student’s grade. It reads three test scores (between 0-100) and calls a function the calculate and return a student’s grade based on following rules:
(a)   If the average score is 90% and more, the grade is ‘A’
(b)   If the average scores 70% or more & less than 90%, it checks the third score. If the third score is more than 90%, the grades is ‘A’ otherwise than grade is ‘B’
(c)   If the average score is 50%, it checks the average of second & third scores. If the average of them is greater than 70%, the grade is ‘C’, otherwise it is ‘D’.
(d)   If the average score is less than 50%, then the grade is ‘F’

The program’s main() contains only call statements. At least 3 subfunctions are required:
1.   One function to read score
2.   One to determine the grade
3.   One to print the result

Hai Dear Mazlin !

Thanks for your question , Here is the code i have written as per the needs !!

#include<iostream.h>

int scores[3];

{
for( int i = 0 ; i < 3 ; i++){
cout<<"Enter Mark :";
cin>>scores[i];
}

}

int CalcResult()
{
int total = 0;
float average = 0.0;

for( int i = 0 ; i < 3 ; i++)
total += scores[i];

average =(float) total/3.0;

if( average >= 90.0)
return 1;
else if( average >= 70.0 && average <= 89.9)
{
if( scores[3] >= 90)
return 1;
else
return 2;
}
else if ( average >= 50.0 && average <= 69.9)
{
if( ((scores[2] + scores[3] )/2.0) >= 70.0)
return 3;
else
return 4;
}
else if( average <= 49.9)
return 5;
}

void PrintResult()
{

{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}

}

void main()
{
PrintResult();
}

Note : Its working fine , bur i didn't test this program ,i kindly request you to do the same  and revert me in case of issues !

Thanks and Regards !
Prince M. Premnath

C++

Volunteer

#### Prince M. Premnath

##### Expertise

Years of research in C/C++ Will bring you all facts regarding , OOPS , SVGA , MOUSE , BIOS , IVT , Feel free to query me :-)

##### Experience

More than 5 years

Education/Credentials
MCA