Numeric Data Validation in C++ -


i have looked everywhere can't seem find , implement input validation takes in integers, have code running fine problem since ive added validation code, requires user enter twice before accepts second input, want user have enter in once validation program recognizes not int , displays appropriate message, id appreciative of help!

here's code:

cout<<"please enter first value: \n"; cin>>a;  //error checker check if input number while(!(cin >> a)) {         cin.clear();     std::cin.ignore(numeric_limits<streamsize>::max(), '\n');     cout << "invalid input. please try again: "<<endl; } 

you trying cin>>a once before while loop , again in while loop condition. remove initial extraction.

cout<<"please enter first value: \n"; // cin>>a; <- remove  //error checker check if input number while(!(cin >> a)) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -