1.11M Members

Integer checking?

 
0
 

User is supposed to type an input, and if it's not an integer, the user needs to type another.
This repeats 3 times for 3 inputs which go inside an array.

The integer checking works, but the problem is that when i display the 3 integers, they are all the same number (the first correct input). Idk what's wrong. I've tried cin.clear() and cin.sync()...

for(int i=0;i<3;i++){
cout<<"Enter your "<<text[i+6]<<": ";
cin.sync();
cin.clear();
cin>>inInt[i];
if(!cin){
cout<<"\nPlease enter a valid integer.";
i--;
system("pause");}
system("cls");}
 
0
 

What does your display loop look like?

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: