| cascade384 (34) | |||
Hey I'm having trouble getting the for loop to work, it's pretty similar to another for loop I did earlier only the previous worked fine. The count list is one throught ten, but will show the same distance output for five iterations if 5 is entered as seconds. Any tips will be greatly appreciated.
| |||
|
|
|||
| Cerburos (45) | |||
|
It might be my noob eyes, what are you trying to do with this code? Whats wrong with the for loop? Distance = 4.9 * time^2 where time = a number between 1-10 entered by the user. What is the purpose of fallingdistance() Seems like a lot of extra work just to say
| |||
|
|
|||
| grcunning (117) | |
|
The problem is that every time the loop iterates, say with time=5, the value of distance will always be calculated using the same time value. If you change the distance calculation to: distance = .5 * 9.8 * pow(count,2.0); then each time you cycle through the loop, the value of distance will change based on the value of count, from 1 to time. | |
|
Last edited on
|
|
| cascade384 (34) | |
| Yes cerburos it is more work , however I have to learn to how to use many functions as opposed to just using one function. This prblem called for a function to take input and send back to the main function. | |
|
|
|
| cascade384 (34) | |
| I used [distance = .5 * 9.8 * pow(count,2.0);] instead of [distance = .5 * 9.8 * tim(count,2.0);] and the runs nice and clean, thanks for the help. | |
|
|
|