New to C++ , How to add check if user inputs string or char instead of int

  • Thread starter Thread starter Ahmad123a
  • Start date Start date
A

Ahmad123a

Guest
I want to add the check-in my c++ code that user can not enter not integral values in reg. If he inputs, he is prompted again. I saw the solutions in the stack overflow that was of <g class="gr_ gr_37 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" data-gr-id="37" id="37">2011 .</g> Is there some modern or good way now or is it same?

I tried using <g class="gr_ gr_34 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="34" id="34">fdigit</g>() in <ctype.h

// Example program
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
int x;
cout<<"Type X";
cin>>x;
if(!isdigit(x))
{
cout<<"Type Again";
cin>>x;
}
}

but it <g class="gr_ gr_35 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="35" id="35">didnt</g> worked

here is my actual problem where I want to add check

cout << "Type Reg # of Student # " << i + 1 << endl;
do
{
cin >> arr[j];
} while (arr[j] < 999 || arr[j] > 9999);

where i and j are int dec. in for loop. I just want to add check that input is not <g class="gr_ gr_44 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" data-gr-id="44" id="44">string</g> or something like this.

Continue reading...
 
Back
Top