Hi im a freshman college student in C programming. We are learning how to use functions. For some reason no one in my Lab can get it to work and im the closest. Here is my code:
Code:
/*
Ryan Houlihan
Lab2
The goal of this program is to read in a number between 0 and 100 and
print it out as a letter grade.
*/
#include <stdio.h>
int getScore(); /* Function that converts number score to a letter grade */
char convertGrade(int numScore); /* Function that converts inputed number grade to a letter grade */
void showGrade(int numScore, char letterGrade); /* Function that prints out the letter grade */
int main() /* Calls the other three functions */
{
getScore();
}
int getScore() /* Asks user to input a grade form 0-100 8/
{
int numScore;
printf("Please enter a grade from 0-100:\n ");
scanf("%d", &numScore);
return(numScore);
}
char convertGrade(int numScore) /* Converts number score to a letter grade */
{
int numScore;
if (numScore >= 0 && numScore <= 59)
showGrade(numScore,'F');
else if (numScore >= 60 && numScore <= 69)
showGrade(numScore,'D');
else if (numScore >= 70 && numScore <= 79)
showGrade(numScore,'C');
else if (numScore >= 80 && numScore <= 89)
showGrade(numScore, 'B');
else if (numScore >= 90 && numScore <= 100)
showGrade(numScore, 'A');
else
showGrade(numScore, 'Z');
return(0);
}
void showGrade(int numScore, char letterGrade) /* Prints out the letter grade */
{
if(letterGrade == 'Z')
printf("%d is not a vaild number. Please enter a number between 0 and 100\n", numScore);
else
printf("Your grade, %d, is equal to an %c\n", numScore, letterGrade);
}
It complies fine but it just prints this. :
-1074170612 is not a vaild number. Please enter a number between 0 and 100
Any help is appreciated. I have been trying to figure this out for the past 3 hours with no luck. Ugh.