Why can't I get my code to print the correct letter grade for my test scores

0 Number Double07 · May 17, 2015
I want my code to print letter grades for my test scores from three exams, quiz, midterm, and a final.  An A is 90 and above, B is 70 to 89.9999999, C is 50 to 69.999999, the rest is failing.  To summarize what I have done, I created two functions, one to calculate the average of the test scores, and the other to give a letter grade corresponding to that average.  However, my letter grade keeps giving me the @ symbol.  I've been stuck on this for 35 minutes now.  


using namespace std;

float finalScore (int x, int y, int z);
char letterGrade (float x);

float finalScore (int x, int y, int z)
   float average;
   float total_score = static_cast (x+y+z);
   float tests = 3;
   average = total_score/ tests;
   return average;

char letterGrade (float x)

   char Grade;
   if (x >= 90)
       char Grade = 'A';
   else if (x >= 70 && x < 90)
       char Grade = 'B';
   else if (x >= 50 && x < 70)
       char Grade = 'C';
       char Grade = 'F';

   return Grade;


int main()

2. Write a program that determines a student’s grade.
The program will read three types of scores (quiz, mid-term, and final scores)
and determine the grade based on the following rules:

-if the average score =90% =>grade=A
-if the average score >= 70% and  grade=B
-if the average score>=50% and grade=C
-if the average scoregrade=F

int nquiz;
int nmid_term;
int nfinal;
float faverage;
char Grade;

cout  nquiz;

cout  nmid_term;

cout  nfinal;

faverage = finalScore(nquiz, nmid_term, nfinal);


Post a Reply


- page 2
Oldest  Newest  Rating
0 Number Double07 · May 20, 2015
Michael!!!  I haven't covered pointers yet, geez!  lol, just kidding, I'm not mad, I'll just start reading over pointers tonight so I can understand your pretty artwork.  I'm inspired now.

Oh, and sorry, I realize the code did not paste correctly, I will resend it when I get home so you guys can try out my initial jacked up code, lol.  I need more work with putting  returning chars via a function.  Like I said earlier, I was able to get my code to work returning an int from a function for the letterGrade and then using static_cast to convert the ints to char in the main function.  But, I'd like to know how to do it the original way I intended to too.  

1 more thing, the null character is an unprintable character, so I would not see anything if I printed it out.  The @ symbol is Ascii code 64, 1 code away from one of my target ascii code 65 which stands for 'A'.  Coincedence or not, hmmmmmm.

Yea buddy,

Gucci Mane
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator