McJohnny OWhite McJohnny OWhite - 17 days ago 7
Java Question

repeat "readInt" till the input is wrong

i want to solve a small problem, but for me its a big one :D

"This program should start by asking the user for N; if N is outside of the desired range, the user should be asked again."

ACM libary:

int N = readInt("Enter N (0 <= N <= 10): ");

while (N < 0 ^ N > 10) {
readInt("Enter N (0 <= N <= 10): ");
if(N > 0 && N < 11) break;
}


If the User typed for example "-1", the program asked him again. This is good.
But the second input (for example "2") don't breaks the while loop. :-(

Thanks a lot, for helping a beginner like me ^^

Answer

You must assign your second readInt to a variable like:

N = readInt("Enter N (0 <= N <= 10): ");