Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Limit the int values a user can input  RSS feed

 
D diller
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get a user to input a value between, say, -50 and +50. Is there an easy way to do this, or will I most likely be stuck to using an if sequence that displays an error message and rejects the number if it's outside that range? Then on the else part of it, I could have it enter correctly.

Is there an easier way to do this, by specifying the allowed parameters?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's basically the idea, although you would probably be better off using a "while" loop, since you don't know how many times the user will enter invalid input.
 
D diller
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, definitely would have figured that out after running it a few times with unacceptable values. But that does clear up my confusion. Thanks a bunch for your help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!