• Post Reply Bookmark Topic Watch Topic
  • New Topic

select case nested inside an if statement  RSS feed

 
Nikki Smith
Ranch Hand
Posts: 65
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I'm having is that with my If statement un-commented out, the select statement drops straight to the default and skips all the other cases. Right now I have the If statement commented out and the select case works fine. If the user enters a distance value less than 0 or greater than 10,000 I need it to stop and display an error message. Likewise, if the user doesn't enter either air, water, or steel I need it to display an error message.

==========================================

 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome to the coderanch Nicole
update your code :

hope it help
Puspender
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

I think you are trying to do too much all at once. Start by getting the input, not in the main method. The main method should ideally contain one statement. That starts off your app, which calls separate methods for keyboard input, choice, printing messages, calculating the speed, etc. By the way, your comment is not quite right; 1100 is how far (in feet) sound travels in air in 1 second.
Added later:- [If you split up the task into multiple methods you can run each method individually and see they each work, before you try putting it all together.]

And the example in the link does show only one statement in the main method; the first line is a declaration. You can run those together as a single line:-
new Foo().startApp();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!