-1

I trying something really simple but in same time a little bit hard for me. I want to let user to insert number via console and if is not number to tell that is not and give chance to insert again while is number. Here is what I've made so far

int a;

 cout<<"enter a: ";
 cin>>a;
 while (!isdigit(a)); {
    cout << "\n ERROR, enter a number" ;
    cin.clear();
    cin >> a;
 }

system("Pause");
return 0; 

Now I get error that is not number but the program is terminate. I can't insert again and must start it again.

Gordon
  • 11
  • 1
  • 6

1 Answers1

2

Remove the ; from the while line...

Then take care of the value you are testing for beeing a digit – isdigit expects a character, while you're providing the whole integer read from input (say, 57204, which is not a character code).

CiaPan
  • 9,381
  • 2
  • 21
  • 35