disallow negative numbers..

is there an exception for negative numbers?

i'm trying to create a program which takes the user's input like this:

input a positive integer: 5

System prints out "good job" after

then repeats the question until the user types 0.

I got that part working but if i input something like this:

input a positive integer: -2

System prints out "Positive integer please!" and then takes the users input again until they input a positive integer or 0, then the program will output the other statements.

i'm thinking of creating a while loop but i don't know where to put it so that the program reverts back to "input a positive integer" after the person does so instead of "Positive integer please!"

Thanks in advnace!

[772 byte] By [RAWR-itsanONIONa] at [2007-11-27 5:10:39]
# 1
onions are delicious. especially sizzled over steak. but anyway...do{print(Enter number)number = input number} while(!number < 0)
TuringPesta at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 2
Ya they are and your making me hungry ^_^thanks for the quick response, but I do have some questions about that. When do you know when to use a do loop with a while loop instead of just a while loop by itself and why number = input number, what does it do and why is it there?
RAWR-itsanONIONa at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 3
it was just pseudo-code. and not a great solution at that.while versus do/while is really a case by case decisionbut it all boils down to putting the logic at the beginningor end of a block.
TuringPesta at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 4
do{print(Enter number)number = get user input} while(number < 0)Delete the ! or swap the logic to >
floundera at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 5
i thought he wanted to break if the user entered a negative.my hearts just not in it tonight.
TuringPesta at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 6
> Ya they are and your making me hungry ^_^you realize thats the ONLY thing i can think about now!
TuringPesta at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 7
Don't forget the gravy. Lots of gravy.
floundera at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 8
> Don't forget the gravy. Lots of gravy.Someone name a country, we're all meeting up at a diner.
TuringPesta at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 9
If we are talking food, Chile would be appropriate.
floundera at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...
# 10
> Someone name a country, we're all meeting up at a diner.Moldova.
DrClapa at 2007-7-12 10:30:51 > top of Java-index,Java Essentials,Java Programming...