0

I want to solve a small problem, but for me it's a big one.

"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 library:

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 prompts him for input again. This is good.
But the second input (for example "2") doesn't break the while loop.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

2

You must assign your second readInt to a variable like:

N = readInt("Enter N (0 <= N <= 10): ");
JFPicard
  • 5,029
  • 3
  • 19
  • 43