Forums Register Login

Why does my 'd' variable stay at zero?

+Pie Number of slices to send: Send



I am definitely new to programming any language. I am apologizing in advance. But I am trying to create a program that takes 3 numbers from keyboard input and then displays them from lowest to highest. This compiles and runs but d is staying at zero(I think). It correctly orders the 'e' and 'f' no matter the order you enter numbers. I am stumped please help.



[HENRY: Added code tags]
+Pie Number of slices to send: Send
The value of d only gets changed inside your while loop and you will only enter the while loop if one of d, e or f is not zero. As you initialise them all to zero before the loop, the code in the loop will never be run.
+Pie Number of slices to send: Send
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

And welcome to JavaRanch!
+Pie Number of slices to send: Send
Don't think we're beating up on you, but I'd like to make another suggestion. always always ALWAYS use braces. Some day, you're going to revisit some code and thing "I need to do something else here, like a System.out.println()". You'll stick it in, and things will REALLY go crazy because something won't be in the loop anymore. It really doesn't cost that much to always have them, and personally, I find code much easier to read with them in there.

Indentation alone isn't enough to see what is part of what. in your code below, your "if" on line 33 in indented more than your 'while' on line 20, but less than the if on line 23. it's confusing as to whether this should be inside the loop or not.
+Pie Number of slices to send: Send
 

fred rosenberger wrote:Don't think we're beating up on you, but I'd like to make another suggestion. always always ALWAYS use braces. Some day, you're going to revisit some code and thing "I need to do something else here, like a System.out.println()". You'll stick it in, and things will REALLY go crazy because something won't be in the loop anymore. It really doesn't cost that much to always have them, and personally, I find code much easier to read with them in there.

Indentation alone isn't enough to see what is part of what. in your code below, your "if" on line 33 in indented more than your 'while' on line 20, but less than the if on line 23. it's confusing as to whether this should be inside the loop or not.



+1 on this. Braces are a coder's best friend, in my opinion.
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1244 times.
Similar Threads
Scanner
what's wrong with this code?
Confused in console please help
Really long post about multidemensional arrays
question on array and printing
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 20:35:50.