Originally Posted by
vart
I do not beleive you. You ignoring the return value of getScore and convertScore functions and the not initialized variables
Your completely right. Our lab assignment was to write the program normally and get it to function properly. Then we had to re-write it with functions. So when we ran it i accidentally ran the first version, the old working version without functions, but not the new version that included functions. I finally got it to work though. It was a simple fix having to do with the main function. Cant believe i spent 4 hours and didn't realize the problem.
And here it is for anyone interested in how it looks completed.
Code:
/* Ryan Houlihan
Lab 2
The purpose of this program is to use functions to convert a number between 0 and 100 to a
letter grade of either A, B, C, D, or F.
*/
#include <stdio.h>
int getScore(); /*Declaring the first function */
char convertGrade(int numScore); /*Declaring the second function*/
void showGrade(int numScore, char letterGrade); /*Declaring the third function*/
int main() /*Calls on the other 3 functions*/
{
int numScore;
int letterGrade;
numScore = getScore();
letterGrade = convertGrade(numScore);
return (0);
}
int getScore() /*Asks users to input a number*/
{
int numScore;
printf("Please enter your numeric exam score and press return> \n");
scanf("%d",&numScore);
return(numScore);
}
char convertGrade(int numScore) /*Converts inputed number into a letter*/
{
if (numScore >=90 && numScore <=100)
showGrade(numScore,'A');
else if (numScore >=80 && numScore <=89)
showGrade(numScore,'B');
else if (numScore >=70 && numScore <=79)
showGrade(numScore,'C');
else if(numScore >=60 && numScore <=69)
else if (numScore >= 0 && numScore <= 59)
showGrade(numScore,'F');
else
showGrade(numScore,'Z');
return(0);
}
void showGrade(int numScore, char letterGrade) /*Prints out the letter coresponding to the inputed number*/
{
if (letterGrade=='Z')
printf("%d is not a valid number. Please enter a number between 0 and 100.\n", numScore);
else
printf("Your original numeric score of %d is a(n) %c grade.\n",numScore,letterGrade);
}