Ahem, I suggested it first! :D
Actually it's a well-known solution, so neither of us deserves praise . . . .
Printable View
Ahem, I suggested it first! :D
Actually it's a well-known solution, so neither of us deserves praise . . . .
Ah, it got lost somewhere in the thread! I see it now.
You outsmarted as all :p Actually, I didn't know there was such an optimization. Well, I don't really work with loops that way. Often... anyway... I think...
lmao.. found my stupid mistake..
thanks guys..
one more quick questions guys
how can i make a program reject a negative value from being stored in array. e.g if a user inputs a negative value, how can i display a message that will tell the user to enter a positive value.
Guess. Maybe something along the lines of
- Get a number from the user.
- If the number is negative:
- Print an error message.
- Get another number from the user.
- Go to step 2.
- Viola! You have your number.
That can be simplified, of course, for example if you use a do-while loop instead . . . but try that and see what happens.