Thread: parameter passing..??

  1. #1
    UpTooLate
    Join Date
    Feb 2008
    Location
    New York
    Posts
    32

    Question parameter passing..??

    I am having trouble figuring out how to get this program to work correctly and was wondering if someone could give me a little guidance? I know the problem is in the last function Grade::getWeightedGrade() but I can't figure out what I am doing wrong. The program runs correctly but instead of returning the right score it returns zero. The score is supposed to be based upon the ( score of the test * (weight / 100) for both grade1 and grade2 and then these totals are added together to give the final score....
    Here is what it should run like:
    Enter Type: Midterm
    Enter Score: 86
    Enter Weight: .40

    Enter Type: Final
    Enter Score: 97
    Enter Weight: .60

    Your grades are as follows:
    Midterm 86, which counts 40%
    Final 97, which counts 60%
    Your final grade is: 92.6




    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class Grade
    {
          public:
                 void enterGradeInfo();
                 void showGradeInfo();
                 double getWeightedGrade();
                 
                 
          private:
                  int mWeight;
                  int mScore;
                  string mType;             
    };
    
    int main()
    {
        Grade grade1;
        Grade grade2;
        grade1.enterGradeInfo();
        grade2.enterGradeInfo();
        cout << "Your grades are as follows:" << endl;
        grade1.showGradeInfo();
        grade2.showGradeInfo();
        cout << "Your final grade is " <<  grade1.getWeightedGrade + grade2.getWeightedGrade;    
        cout << endl;
     
      
        system("pause");
        return 0;
        
        
    }
    
    void Grade::enterGradeInfo()
    {
         cout << "Enter type: ";
         cin >> mType;
         cout << endl;
         cout << "Enter Score: ";
         cin >> mScore;
         cout << endl;
         cout << "Enter weight: ";
         cin >> mWeight;
         cout << endl;
    }
     
    
    void Grade::showGradeInfo()
    {
         cout << mType << " which counts for " << mWeight << "%" << endl;
    }     
    
    double Grade::getWeightedGrade()
    {
         return mScore * (mWeight/100) ;       
    }

  2. #2
    Registered User
    Join Date
    Jun 2007
    Posts
    41
    Without looking too much could it be precision of your variables?

    int mWeight;
    int mScore;
    it could be rounding your math off to ZERO ?

    try switching them to double or

    Code:
    mScore * (mWeight/100.0f)
    or
    float(mScore) * (mWeight/100.0f)
    mWeight/100 = 0.5 = round off to zero I'm guessing
    m_Score * 0 = ZERO
    etc..
    Last edited by HyperShadow; 02-27-2008 at 09:38 PM.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    getWeightedGrade is a method, and needs to be called like this (you forgot the parentheses):

    Code:
    cout << "Your final grade is " <<  grade1.getWeightedGrade() + grade2.getWeightedGrade();

  4. #4
    UpTooLate
    Join Date
    Feb 2008
    Location
    New York
    Posts
    32

    Wink thank you

    wow one little decimal after all of that.... thank you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parameter passing and pointers
    By pokiepo in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 12:13 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM