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;
}
}
CodePudding user response:
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';
CodePudding user response:
you are using the function
findLetter(grade)
I think you should pass the score to it and the grade is of type char and assign the return of that function to the grade so your code will be like that
int main()
{
int score; //taken as user input
char grade;
printf("\tEnter your numberical grade: ");
scanf("%i", &score);
grade = findLetter(score);
printf("Your grade is a %c", grade);
return 0;
}