Hello again,
Here's my 1st attempt to convert that program to use functions with some added functionality.
Code:
#include <stdio.h>
/* Prompts user to enter the score */
int getScore(int numScore);
/*Converts a numberic score to a letter grade */
char convertGrade(int numScore);
/*Displays the original numeric score, the corresponding letter grade
*if the score is valid, and an appropriate eror message if the score
*if the score is not valid
*/
void showGrade(int numScore, char letterGrade);
int
main(void);
{
char letterGrade, printGrade, showGrade, convertGrade;
int numScore;
getScore(numScore);
letterGrade = convertGrade(numScore);
printGrade = showGrade(numScore);
return(showGrade);
}
/*Fuction that prompts user to enter the score */
int getScore(int numScore);
{
printf("Please enter numeric grade and press return>");
scanf("%d", &numScore);
}
/*Function converts a numeric score to a letter grade */
char convertGrade (int numScore, char letterGrade);
{
if(numScore >= 90)
letterGrade = 'A';
else if(numScore >= 80)
letterGrade = 'B';
else if(numScore >= 70)
letterGrade = 'C';
else if(numScore >= 60)
letterGrade = 'D';
else if(numScore <= 59)
letterGrade = 'F';
else if(numScore > 100 && numScore < 0)
letterGrade = 'Z';
}
/*Function prints out the letter grade */
{
void showGrade(int numScore, char letterGrade);
if(letterGrade='Z')
printf("\nYour score of %f is not valid.\n", letterGrade);
else
printf("\nYour score of %f is a %c grade.\n", numScore, letterGrade);
}
When I try to compile the code, i get the following errors.
Code:
grade_calc.c:19: error: syntax error before '{' token
grade_calc.c:24: warning: parameter names (without types) in function declaration
grade_calc.c:24: warning: data definition has no type or storage class
grade_calc.c:26: error: initializer element is not constant
grade_calc.c:26: warning: data definition has no type or storage class
grade_calc.c:28: error: too few arguments to function `showGrade'
grade_calc.c:28: error: void value not ignored as it ought to be
grade_calc.c:28: error: initializer element is not constant
grade_calc.c:28: warning: data definition has no type or storage class
grade_calc.c:30: error: syntax error before "return"
grade_calc.c:36: error: syntax error before '{' token
grade_calc.c:38: error: syntax error before string constant
grade_calc.c:38: error: conflicting types for 'scanf'
grade_calc.c:38: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
grade_calc.c:38: error: conflicting types for 'scanf'
grade_calc.c:38: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
grade_calc.c:38: warning: data definition has no type or storage class
grade_calc.c:43: error: conflicting types for 'convertGrade'
grade_calc.c:8: error: previous declaration of 'convertGrade' was here
grade_calc.c:43: error: conflicting types for 'convertGrade'
grade_calc.c:8: error: previous declaration of 'convertGrade' was here
grade_calc.c:44: error: syntax error before '{' token
Any suggestions??