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.
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.
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.
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.
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.
Post by:autobot
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