Uhm, first of all your title references one error and your question shows another. Both are legitimate so let’s fix both, shall we?
The thing is the C4716 error message tells you exactly what the error is: you just have to read it. It says that the function student::standing()
claims to return a string
but doesn’t. Of course, that’s not the only issue. The other problem, which you claim is C2134 (but is likely C4390) is caused because you you put a semicolon after you if
which isn’t right. This code:
if(my_credits <= 60.00);
{cout << "Sophomore";}
is the same as this code:
if(my_credits <= 60.00)
/* do nothing if my_credits are less than or equal to 60 */
{
/* and then always print "Sophomore" */
cout << "Sophomore";
}
Chances are that what you really want is this:
string student::standing() const
{
if(my_credits >= 90.00)
return "Senior";
if(my_credits >= 60.00)
return "Junior";
if(my_credits >= 30.00)
return "Junior";
return "Freshman";
}
For future reference, if you had searched on Google for C4390, you would have landed on an MSDN page describing this error which includes an exact description of the issue, along with the very mistake you made.
Similarly, if you had Googled for C4716, you would have landed on another MSDN page describing that error which again includes an example that’s very close to what your mistake.
Finally, in this code:
string student::name() const
{
{return my_name;}
}
What is the point in those extra curly braces? They don’t really hurt anything, but they just serve no conceivable purpose, except to confuse. Remove them:
string student::name() const
{
return my_name;
}
3
solved Incorrect output [closed]