This site requires JavaScript, please enable it in your browser!
Greenfoot back
newprogramming
newprogramming wrote ...

2014/4/17

need help trying to figure out how to count how long the longest line is

newprogramming newprogramming

2014/4/17

#
Need to move to west to east going over hurdles of trees which are all a different size, the 3rd line is the longest in the 7th column however when i use the for loop it does count the longest line http://i910.photobucket.com/albums/ac307/djEthen/clara.png need help please
danpost danpost

2014/4/17

#
If it is only the length of the longest line that needs to be determined (that is, which line does not matter), then you only need two int fields -- one to hold the longest line found so far; and one to hold the running count of the line being counted (a third int field would be required to hold the column number of the longest line, if needed). If when turning, if kara ends up facing north, add one to the running count; If kara ends up moving east, compare the value of the running count with the value of the longest line found so far. - if the running count is greater, set longest line found to running count and save current column if needed If kara reaches the clover, display final results and stop the program. I do not see a need for a 'for' loop in the code. If still are having problems, post the code you are using (use the 'code' link below the 'Post a reply' box to insert your code into the post) and state what you are having trouble with. If you are getting error messages, post them in their entirety.
You need to login to post a reply.