Thread: Help with array

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    7

    Help with array

    I need help using an array to do relation between elevation and temperature.
    Attached Images Attached Images Help with array-capture-png 

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,548
    What exactly is the help that you have in mind?
    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. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    7
    can you give me an example program of how to use an array for this type of problem? Having a slope and how to pick numbers off of it when the user asks for it?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,548
    Suppose we had a table mapping student assignment grade cutoffs to the grade letters, and given the student's assignment grade as a numeric value, we wanted to find out what the grade letter for the assignment should be. We might come up with an algorithm like this:
    Code:
    grade_cutoffs = {90, 70, 50, 0}
    grade_letters = {'A', 'B', 'C', 'F'}
    i = 0
    loop while i < number of grade_cutoffs
        if grade > grade_cutoffs[i]
            grade_letter = grade_letters[i]
            break
        increment i
    So, if the student scored 60 points as the grade, the algorithm will loop until i = 2, upon which 60 > 50, so grade_letter will be 'C'.

    EDIT:
    Actually, this is not a terribly good example because you're dealing with a slope and need to use linear interpolation as described in the instructions. But ehh... what have you tried? I came up with this as it looked like you didn't even know how to use arrays to get corresponding values, and if indeed you don't, you should attempt this first.
    Last edited by laserlight; 10-17-2018 at 07:34 PM.
    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

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I might be misinterpreting what you're saying, but I think you need to realize that the slopes aren't read from the table; you're using the numbers from the table in the formula at the top of your snippet.

    I would suggest making sure you know how to get the five sample outputs from the five sample inputs; if you can do that, then I would think you would be a long way toward writing it out in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 07-31-2013, 12:15 AM
  2. Replies: 3
    Last Post: 05-09-2012, 06:41 AM
  3. Replies: 2
    Last Post: 03-20-2012, 08:41 AM
  4. Replies: 9
    Last Post: 08-23-2010, 02:31 PM
  5. Replies: 6
    Last Post: 11-09-2006, 03:28 AM

Tags for this Thread