When you have a function that returns nothing, both the function prototype and function definition need to specify a return type of "void".
Todd
Printable View
When you have a function that returns nothing, both the function prototype and function definition need to specify a return type of "void".
Todd
When I type return void, it says:
(52) : warning C4033: 'outputToScreen' must return a value
One last comment on your (now) "if / else" ladder... :)
You don't need the last "if", just let the 'A' grade be an all-inclusive "anything 90 or above" situation. If someone gets a 101 for a score, your current program will return an uninitialized value.Code:int calcLetterGrade (numgrade)
{
int lettergrade;
if (numgrade < 60)
lettergrade = 'F';
else if (numgrade <70)
lettergrade = 'D';
else if(numgrade < 80)
lettergrade = 'C';
else if (numgrade <90)
lettergrade = 'B';
else if (numgrade <100)
lettergrade = 'A';
return lettergrade;
}
Todd
That's where I'm totally confused. How do I correct the problems with the outputToScreen function? At least give me a hint! haha
Ok, I edited the program and completely took out the outputToScreen function, and placed what was needed in the main function. Now, when I enter the numerical value for the grade, the lettergrade value always outputs as 70. Why is this?
Code:
#include<stdio.h>
#pragma warning(disable:4996)
int getNumGrade ();
int calcLetterGrade();
int main (void)
{
int numgrade = 0;
int lettergrade = 0;
char cgoAgain = 'y';
printf ("Enter numerical grade value now:");
numgrade = getNumGrade ();
lettergrade = calcLetterGrade();
printf ("\n When numerical grade is %d,",numgrade);
printf ("letter grade is %d.", lettergrade);
while (cgoAgain =='y' || cgoAgain == 'Y')
{
printf("\nDo you want to enter another grade?");
scanf("%c%*c",&cgoAgain);
}
return 0;
}
int getNumGrade()
{
int numgrade = 0;
scanf("%d%*c",&numgrade);
return numgrade;
}
int calcLetterGrade (numgrade)
{
int lettergrade;
if (numgrade < 60)
lettergrade = 'F';
else if (numgrade <70)
lettergrade = 'D';
else if(numgrade < 80)
lettergrade = 'C';
else if (numgrade <90)
lettergrade = 'B';
else if (numgrade <100)
lettergrade = 'A';
return lettergrade;
}
Two problems now. Besides the fact that any number produces a lettergrade of 70, when I type "y" to enter another letter grade, it doesn't ask for a new numerical value, it just asked if I want to type in another letter grade. There's obviously a problem with the loop, but i'm unsure what it is.
You are calling calcLetterGrade without a parm:
Yet your function prototype, and function definition state that you should be passing a parm.Code:lettergrade = calcLetterGrade();
You should be getting compiler warnings about this stuff.
Todd
You seem to be confused about prototypes.
A prototype is information that tells the compiler how the real function, which is defined later, looks like. Therefore, they should be indentical.
A pretty good rule is to copy the first line of the definition and paste it as your declaration and append a ; afterwards.
Remember: The function prototype and definition MUST match or you WILL get errors or undefined behavior.