Computer Science Canada How to output specific information only using arrays |
Author: | tristanbryce7 [ Tue Nov 13, 2012 4:22 pm ] | ||||
Post subject: | How to output specific information only using arrays | ||||
Hello, I have a problem , In the following program, I get the information for 10 students and their heights of a data base, and the program calculates the average height number . Now my problem is, how do I get the problem to after it gets the 10 Peoples data, only make it output the names of the peoples whose height is higher than the average, i m thinking you would need to use a loop and put in it somewhere if height > average, but I have no clue what to do after that, Any one know how to do it ? I am new to arrays so I am kind of confused.
|
Author: | Tony [ Tue Nov 13, 2012 4:28 pm ] |
Post subject: | RE:How to output specific information only using arrays |
If you are confused about arrays, you should revisit some of the tutorials available from the Turing Walkthrough. |
Author: | Insectoid [ Tue Nov 13, 2012 6:44 pm ] |
Post subject: | RE:How to output specific information only using arrays |
Quote: if height > average, but I have no clue what to do after that
Well, what do you want the computer to do when height > average? |
Author: | tristanbryce7 [ Tue Nov 13, 2012 8:41 pm ] |
Post subject: | Re: How to output specific information only using arrays |
I am pretty clear on what we 've learned in arrays so far(which is not much lol), just not how to that specific option, and I want the program to only output the heights that are above the average I tried putting it in a loop as (Sorry, I do not have the Syntax for showing Turing Memorised) loop if height > average then put name end loop something along those lines, It didnt go to well |
Author: | Insectoid [ Tue Nov 13, 2012 9:07 pm ] |
Post subject: | RE:How to output specific information only using arrays |
You know how to use a counter variable, as shown in your first post. Use that. Quote: if height > average
height is an array, remember? You can't compare it like that. You have to compare one specific element of the array using the array syntax, which you also know to be "height (x)" where x is an integer. name is also an array, so it follows the same rules. You're almost there, you just need to add the proper array syntax and a counter variable (or use a for loop, which is actually the better solution). |
Author: | Tony [ Tue Nov 13, 2012 9:10 pm ] |
Post subject: | RE:How to output specific information only using arrays |
I would suggest that you start with printing all of the heights recorded in your array, and worry about filtering it (above average or not) later. How would you print every height? |