2

I'm stuck and everything is correct except the Grade wont display, any help would be appreciated!

#include <iostream>

using namespace std;

void calcScore(int grade, double&total);

int main()
{   
    //declare variables
    int score       = 0;
    int totalPoints = 0;  //accumulator
    char grade      = ' ';

    //get first score
    cout << "First score (-1 to stop): ";
    cin >> score;

    while (score != -1)
    {
        //update accumulator, then get another score
        totalPoints += score;
            cout << "Next score (-1 to stop): ";
            cin >> score;
    }   //end while


    //display the total points and grade
    cout << "Total points earned: " << totalPoints << endl;
    cout << "Grade: " << grade << endl;
    return 0;
}   //end of main function


void calcScore(int grade, double & total)
{
    if (total >= 315)
            grade = 'A';
    else if (total >= 280)
            grade = 'B';
    else if (total >= 245)
            grade = 'C';
    else if (total >= 210)
            grade = 'D';
    else
            grade = 'F';
}
rubenvb
  • 74,642
  • 33
  • 187
  • 332
Ryan
  • 21
  • 1

1 Answers1

6

You've tagged this as homework, so I won't show you a code solution. A couple of things for you to look at:

  1. Your calcScore function is never being called anywhere.
  2. You're passing grade to calcScore by value, so you'll be operating upon a local copy of grade within your calcScore function. Is that really what you want?
  3. You've declared grade as char in main, but as an int in the calcScore declaration. Do you understand the relationship between the two?

Good luck! :)

Community
  • 1
  • 1
razlebe
  • 7,134
  • 6
  • 42
  • 57
  • @Ryan In answer to your comment "So what if I did this?": it would behave differently. :) In seriousness, if you don't call calcScore from your main(), it will never be executed. As to the other two points, ask yourself how you will return the `grade` from calcScore. – razlebe Apr 20 '11 at 16:25
  • @Ryan As a further hint, it might help you to spot what's currently going on if you initialise `grade` to something other than a space - for example, to a 'Z'. – razlebe Apr 20 '11 at 18:50