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.

4

1 回答 1

2

您必须将第二个 readInt 分配给如下变量:

N = readInt("Enter N (0 <= N <= 10): ");
于 2016-11-23T16:48:06.153 回答