I need help using an array to do relation between elevation and temperature.
I need help using an array to do relation between elevation and temperature.
What exactly is the help that you have in mind?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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?
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:
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'.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
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.