How can I validate this 5 digit number (zipcode)

I need an easy method for validating a 5 digit number, in this case being a zipcode. Obviously what I tried didn't work as I wanted. Any suggestions would be helpful. Thanks everyone! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

double getRadius(); //Function prototypes for these two functions
double squareRadius(double);


int main ()
{
	
	string name;
	int zipcode;
	double radius, area;
	double PI = 3.14;

	cout << fixed << setprecision(2) << endl;
	cout << "Hello, welcome to the area of a circle calculator!" << endl;
	cout << "What is your name?" << endl;
		getline(cin, name);

	cout << "Great! Welcome " << name << "!" << endl;
	cout << "Before you begin can we please collect your zipcode?" << endl;
		cin >> zipcode;
		
		while (zipcode < 00001 || zipcode > 99999)
		{
			cout << "Invalid zipcode entered." << endl;
			cout << "Please try again." << endl;
			cin >> zipcode;
		}

	cout << "Thank you! Now proceeding to the calculator..." << endl;
		radius = getRadius();
		
	cout << "You entered a radius of " << radius << ", measured in units." << endl;

	area = PI * squareRadius(radius);

	cout << "The area of this circle is..." << endl;
	cout << area << endl;

	system("pause");
	return 0;
}

double getRadius()
{
	double rad;
	cout << "Please enter the radius of a circle." << endl;
	cin >> rad;
	return rad;

}

double squareRadius(double number)
{

	return pow(number, 2.0);

}
A zip code is not an integer. Integers can't start with 0, whereas zip codes can (several places in New York, for example). Make it a string and check that each character is a digit and that it is 5 characters long.
Topic archived. No new replies allowed.