How to stop input after certain characters

I'm trying to get the user to input their 5 digit zip code but my problem is how can I stop the program after the five characters have been inputted. Also how can I only get numbers to be inputted cause so far letters can be inputted as well.
Are you using a loop to input the numbers for the zipcode?

Possibly try using an array of a fixed size

1
2
3
4
int zipcode[]
for (int i = 1; i =<5; i++){
      cin >> zipcode[i];
}
No I'm asking the user directly
1
2
3
int ZipCode; 
cout << "Please Enter 5 Digit Zip Code:"; 
cin >> ZipCode;


the problem is I used cin.fail to make sure numbers are entered but if I input something like 9had it doesn't fail since the first character is a number.
Topic archived. No new replies allowed.