Thread: AVG High/Low test scores

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by BeldenML View Post
    Its funny I think Ive learned more working with you guys than from my professor!
    That shouldn't surprise you...

    Depending on the school you attend, most programming teachers are not programmers.
    They are professional educators following a curriculum.

    Some day when there's a minute or two at the end of class, ask your professor if you can see some of the software he or she has written...
    That should be an interesting moment.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by BeldenML
    I just added a sum-=num before the break so that way it adds whatever negative number the user enters to break the loop.
    Someone gives you a bag of cookies and tells you that you can keep picking cookies one at a time out of the bag and eat them, stopping once you pick a cookie that is not a chocolate chip cookie (those cookies are poisoned). So what you do is pick a cookie. Oh, chocolate. You eat it. You pick another cookie. Walnut. You eat it. As you begin to froth at the mouth, you obtain and consume the antidote to the poison and then finally announce that you are done. Wouldn't it have been safer if you did not eat the walnut cookie to begin with?

    Likewise, why add num to sum before you know that it is non-negative?

    Quote Originally Posted by BeldenML
    My next step is just to print the high/low scores. Where should I start with that? laserlight will the code I have below work?
    Generally, the idea is to keep track of the currently known highest/lowest scores. The interesting part is how you start with a highest/lowest score and then update it

    As a side note: I discourage you from using a controlled infinite loop when you can make sensible use of the loop condition as in my suggestion.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by iceaway View Post
    I would suggest changing the contents of your while-loop a bit. First read the number, then check if it is below zero or not. If it is non-negative, add it to sum and increase the counter, if it is negative, exit the loop.

    I would not use i as a float value here, since it it just a counter and it does not need floating point precision. Instead I would make your avg variable a float, and before printing the average, calculate the average into the avg variable and print that instead.

    Code:
    float avg;
        ...
    avg = (float)sum/i;
    He can also do it in the printf() as he is now...

    Code:
        printf("Average: %0.2f\n", ((float) sum) / i );

  4. #19
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by CommonTater View Post
    He can also do it in the printf() as he is now...

    Code:
        printf("Average: %0.2f\n", ((float) sum) / i );
    Indeed, I just figured he could make use of the avg variable defined previously :-) Somewhere along the line there usually comes a time when you need the avg again, then it's convenient to have it calculated already.

  5. #20
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    Great thanks iceaway! Any tips on where to start for printing high/low input grades?

  6. #21
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by BeldenML View Post
    Great thanks iceaway! Any tips on where to start for printing high/low input grades?
    As laserlight said you need to keep track of each new score, and check to see if it is a new "all time low" or "all time high". If the current score is lower than the previously recorded lowest score, you want to update it. The same goes for the highest score. Try putting some code together and post it here if you are running into problems

  7. #22
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    oh sry I didnt refresh the page and see all the new posts. Common I am going to ask him! lol

  8. #23
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    Hey guys the network at school I was logge dinto and saving my code on is down. Im not sure why but either way its 1am and I need to get at least a few hrs of sleep. I will be right back at it in the morning though so please check back if you get some time. Also I get what you guys are saying about the high/low score but Im not sure where to start. Do I add to the existing loop? Or start a new one? Anyways Im falling asleep so maybe Im just missing the obvious. Talk to ya guys in the morning! Thanks for the help!

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by BeldenML
    Also I get what you guys are saying about the high/low score but Im not sure where to start. Do I add to the existing loop? Or start a new one?
    Because you are not saving the scores read, you must add to the existing loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #25
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    ok Im back on it! laserlight let me TRY to add it into the loop and let me know if im on the right track..THANKS!

  11. #26
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    Tater what does the "Return 0" you added on line 21 do again?

  12. #27
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    Quote Originally Posted by laserlight View Post
    Because you are not saving the scores read, you must add to the existing loop.
    I thought I was saving the scores read as "int num"? laserlight Im kind of confused now..

  13. #28
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by BeldenML
    I thought I was saving the scores read as "int num"? laserlight Im kind of confused now..
    That "saves" the current score.

    Let me put it this way: I pick ten cards at random from a deck of cards. I show you the cards one by one. After showing you the tenth card, I ask you what is the highest number of the cards shown to you. The problem is, you have a bad memory, so you only remember that the number of the last card was 5. So, what is the highest number of the cards shown to you?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #29
    Registered User
    Join Date
    Sep 2011
    Posts
    38
    oh ok I see! Im not sure how to write that code though. should I set high=0 and low=0 and then add another if statement saying
    Code:
    if (num >= high)
    {
            num=high
    }
    Something like that?

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by BeldenML
    should I set high=0 and low=0 and then add another if statement saying
    You're on a right track (there is another way, but stick to this one for now). However, suppose that the lowest score is 10. How would you ever update low to 10 when 0 is less than 10?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. High Low Game with High Scores
    By Bradley Buck in forum C Programming
    Replies: 24
    Last Post: 05-27-2011, 12:42 PM
  2. High Scores - A Dilemma
    By CrazyNorman in forum Game Programming
    Replies: 5
    Last Post: 12-28-2006, 09:01 PM
  3. Solitaire High Scores
    By sean in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 07:15 PM
  4. Help on high scores
    By Gnoober in forum C++ Programming
    Replies: 0
    Last Post: 02-17-2003, 07:28 PM
  5. High Scores
    By Gnoober in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2003, 01:08 PM