1,105,340 Community Members

Integer checking?

Member Avatar
nullifyQQ
Newbie Poster
5 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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");}
Member Avatar
deceptikon
Eternally Awesome
4,675 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 681 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

What does your display loop look like?

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