Hi everyone, first time poster here, i'm just having a bit of trouble understanding one small part of this puzzle:
So this puzzle compiles an array of triangles and calculates the area for each, but my question is, how does it know how to calculate the area when the formula is at the very end? Wouldn't it have to be at the beginning of the while loop for it to be taken into account? I've actually reached up to the end of Chapter 5 in the book, hoping that things would start to become more clear but i keep running in to similar confusion where code at the end of my program affects portions at the beginning. Any help would be greatly appreciated!
Post by:Carey Brown
, Saloon Keeper
The first thing you could do to make it clearer is add proper indentation. Then it would be obvious that setArea() is a method just like main() (maybe you already determined that but indentation would make it jump out at you). So, yes, setArea() appears after the place where it is called in main(). The order of methods inside a class makes no difference.
Post by:Ganesh Patekar
, Saloon Keeper
Welcome to CodeRanch! Thank you for posting the code in code tags.
Since this is your first post, I added proper indentation, see It looks more readable now. Rest is cleared by Carey Brown.
Post by:Stefan Moreno
Great, I think that clears it up, thanks!
Post by:Jared Sachs
I don't think it matters where you put that method since the main just calls it.
This thread has been viewed 219 times.
All times above are in ranch (not your local) time.
The current ranch time is Oct 18, 2018 06:39:58.