0

Related question:

I found a similar question already posted here on stackoverflow but for some reason the answer doesn't work in my case.

My question:

I am not able to get out of the loop in the following code when I enter a non-integer value.

int main(){
  int num;
  do {
      cout << endl << "\tEnter number (enter anything other than a number to exit): ";
      try{
          cin >> num;
      }catch(...){
          break; // I also tried "return 1;", "exit(1);" with no success 
      }
  }while(1);
  return 0;
}

Please note that I am not an expert in c++.

Ahtisham
  • 9,170
  • 4
  • 43
  • 57

0 Answers0