Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing Number to Letter Grades

I am trying to figure out why I cannot get the number to change to a letter. There seems to be something I am missing when returning the char function to the main function, but I cannot figure it out. When I print it, it will not print out the letter. I would really appreciate some guidance.

#include<stdio.h>
#include<stdlib.h>

char findLetter(int grade);

int main()
{
   int score; //taken as user input
   int grade;

   printf("\tEnter your numberical grade: ");
   scanf("%i", score);

   findLetter(grade);

   printf("Your grade is a %i", grade);



   return 0;
}


char findLetter(int grade)
{
  switch(grade/10) 
  {
    case 10:
    {
        return 'A';
        break;
    }
    case 9:
    {
        return 'A';
        break;

    }
    case 8:
    {
        return 'B';
        break;
    }
    case 7:
    {
        return 'C';
        break;
    }
    case 6:
    {
        return 'D';
        break;
    }
    case 5:
    {
        return 'D';
        break;
    }
  return grade;
  }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have not stored the result of findLetter(grade). Change it to:

int main()
{
   int score; //taken as user input
   char grade;

   printf("\tEnter your numberical grade: ");
      scanf(" %d", &score);

      grade = findLetter(score);

      printf("Your grade is a %d", grade);

      return 0;
   }

Also in the function char findLetter(int grade) you are returning grade which is an int, may be change it to

return 'E';

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading