-1

I have a problem with this code. When I run the program, if I enter a number less than an 11-digit number, the program continues without any problems, but when I enter an 11-digit number, I am faced with the message "Enter a number" indefinitely. I get up and I have to close the program. What is the problem?

while (num != -1) {
    cout << "ENTER A NUMBER" << endl;
    cin >> num;
    if (num%2==0) {
        counter++;
    }
}
cout << " number of even numbers are " << counter;
_getch();
return 0;
Burak
  • 2,251
  • 1
  • 16
  • 33
  • 1
    Do you know that `cin >> num` returns something that *should* be checked? – Evg Jan 11 '21 at 08:00
  • Hey . int limitation is 2,147,483,647 your number is probably larger you can define num to be long for example – InUser Jan 11 '21 at 08:01
  • You can `cin` a `string`, then use `atoi` to convert it to an integer. This will prevent the same error when you type an input that is not an integer. – Burak Jan 11 '21 at 08:05

1 Answers1

0

I assume num is int and int limitation is 2,147,483,647 your number is probably larger, you can define num to be long for example or long long.

InUser
  • 1,138
  • 15
  • 22