• Post Reply Bookmark Topic Watch Topic
  • New Topic

For Loop - Integers stuck @ "0"  RSS feed

 
Jordan Grimes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code running correctly in Eclipse all except that it seems no matter where I declare, highest, lowest, average they always seem to stay at "0".

I have a feeling the location of the Initialization is not the error since I have tried moving it to inside differ loops.

Stipulations on writing this code are:
Note: You do not need to use array to save each input score for this lab. A Single loop to read in each grade, compare with the current highest grade, lowest grade, and
calculate the running sum at the same time.

Yes this is homework and I have dug all through my book and the web trying to figure out where I messed up.

 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the following checking for?
 
Jordan Grimes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is checking to make sure the grade entered is between 0and100. But now that you mention it...that creates an infinite loop. I just entered 101 and I get an infinite loop of the println ().
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly...

And besides, it doesn't perform what is required because it never prompts the user for input...
 
Jordan Grimes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i believe I have fixed the Grade Checking issue...and my integers are now display numbers but the while loop runs indefinitely.




 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before I leave the Ranch for the night I will leave you with this hint -> The scope in which you declare variables determine their values upon entering the scope and exiting...
 
Jordan Grimes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks. That makes since. Think I got it now.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you must think about what you are trying to do in terms you understand before translating it to code [English]...

For your range checking problem you are saying -> while the value entered is not in range, get another value

Which translates to:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!