#include "stdafx.h"
#include <iostream>
using namespace std;

int getScore(int& score);
int calculateGrade(int score);

int _tmain()
{
    int courseScore;

    cout << " Line 1: Based on the course score"
         << " this program computes the  "
         << "course grade." << endl;

    getScore(courseScore);

    int calculateGrade(courseScore);

     system ("pause");

    return 0;
}




int getScore(int& score)
{ 
    int num;
    cout << "Line 4: Enter course score: ";
    cin >> num;
    cout << endl << "Line 6: Course score is "
        << num << endl;
    return num;
}

int calculateGrade(int& cScore)
{

    cout << "Line 7: Your grade for the course is  ";

    if (cScore >= 90)
         cout << "A." << endl;
    else if (cScore >= 80)
        cout << "B." << endl;
    else if (cScore >= 70)
        cout << "C." << endl;
    else if (cScore >= 60)
        cout << "D." << endl;
    else 
        cout << "F." << endl;


}

This is what I have. The book says "The function printGrade in Example is written as a void function to compute and output the course grade. The course score is passed as a parameter to the funcion printGrade. Rewrite the function printGrade as a value-returning function so that it computes and returns the course grade. I get the error error C4716: 'calculateGrade' : must return a value what do I have wrong as I'm not seeing it.

Recommended Answers

All 2 Replies

'calculateGrade' : must return a value what do I have wrong as I'm not seeing it.

See how your function getScore uses return to return a value? Where is the return value from calculateGrade? The instructions tell you to return the course grade

int calculateGrade(int& cScore)

Your function, as per the function's definition, has to return an integer value to the user, which is why "int" keyword precedes your function name. When no value is to be returned, you will have to use "void".

Now, to return a value, in this context, you must add a return statement to return a value to the user. In C++, if you've defined a function as an integer-returning one, you MUST return an integral value; this is not optional.

This is your function:

int calculateGrade(int& cScore)
{
cout << "Line 7: Your grade for the course is ";
if (cScore >= 90)
cout << "A." << endl;
else if (cScore >= 80)
cout << "B." << endl;
else if (cScore >= 70)
cout << "C." << endl;
else if (cScore >= 60)
cout << "D." << endl;
else
cout << "F." << endl;
}

You must modify it to return a value which is an integer, instead of printing the value. Here, you are using cout to print the value to console output, whereas, as per the question, you must return the score. You must add return statements instead of cout statements. Return statements are written as:

return var/"char_value"/numerical_value;

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.