Thread: Lowest Score Drop - reference parameter variable, values, etc.

  1. #16
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    Yes, I changed lowest to int in calcAverage.

    Re: the thing that was suggested to fix the e notation (fixed manipulator) - the program crashes before outputting the numbers when I include this.

  2. #17
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    In your "main", right after you get the 5th number, simply print the 5 numbers. If you get the same output as your previous post, then change every "double" to "float" and try again. Let me know the outcome.

  3. #18
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    Okay, after changing the doubles to floats, the program no longer crashes when outputting the scores, but the numbers are still a problem.

    Here is a sample run:

    Please enter a test score. 4
    Please enter a test score. 6
    Please enter a test score. 0
    Please enter a test score. 5
    Please enter a test score. 2

    182395222651967080000000000000000.000000
    0.000000
    0.000000
    0.000000
    3

    Four highest test scores: 182395222651967080000000000000000.000000, 0.000000, 0.000000, 0.000000

    Average: 455988056629917710000000000000000.000000

  4. #19
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Post your updated function that gets the numbers, the problem seems to lie in there I think.

  5. #20
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    Here is getScore:
    Code:
    void getScore(float &tscore)
    {    
         float score;
         
                  cout << "Please enter a test score. ";
                  cin >> score;
                  
         while (score < 0 || score > 100)
             {  
                  cout << "Valid test scores range from 0 - 100.\n";
                  cout << "Please enter a test score. ";
                  cin >> score;
             }  
    }

  6. #21
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by nadroj View Post
    There seems to be a number of issues in the code.

    Code:
    void getScore(double &score)
    {    
         static double tScore; // why do you need this variable at all?
         tScore++; // why do you increment this value, when you're just overwriting it below
         
                  cout << "Please enter a test score. ";
                  cin >> tScore;
                  
         while (tScore < 0 || tScore > 100)
             {  
                  cout << "Valid test scores range from 0 - 100.\n";
                  cout << "Please enter a test score. ";
                  cin >> tScore;
             }  
    }
    In this code your only modifying "tScore", but you should only be modifying "score". Remove "tScore" and read/validate "score" instead.
    You still havent done this, which is the root of the problem.

    After you fix that, you should be able to use either all "floats" or all "doubles", as the problem is in this function above, not the types.

    I offer my time to explain things in the hope that you will read it, learn or understand it, and apply it. If I just tell you every step then you dont learn.

  7. #22
    Registered User
    Join Date
    Nov 2009
    Posts
    11
    Nadroj,

    Thank you, it's finally working!

    I've really appreciated all the time you've taken to help me and especially how patient you've been. I know I've been asking a lot of questions and I made a lot of mistakes, but it's only been because I wanted to learn, not because I wanted anyone to tell me how to do everything. And I did learn. I was confused about the reference parameter because the material in my book is vague. I'd been stuck on this for days and consulted a friend for help before I decided to post here. I'm sorry if I tried your patience, but I really appreciate all the help you gave me and I have learned. Thanks again.

  8. #23
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    No worries, as long as you did learn something in the end.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  3. Problem with OpenGL tutorial
    By 2Biaz in forum Windows Programming
    Replies: 18
    Last Post: 09-16-2004, 11:02 AM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. Passing the variable as a Reference
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-05-2002, 02:35 PM