create random number as zipcode

hey everyone i am trying to create a zipcode I write my code like that and it only show "-2" on the screen what happen to my code I can not find mistake! help!
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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
using namespace std;

class Zipcode {
public:
    Zipcode();
    void createZipcode();
    int getZipcode() const;

private:
    int zipcode;
    int d;

};
Zipcode::Zipcode()
{





}

void Zipcode::createZipcode()
{

zipcode = 10000 + rand() %99999;

}

int Zipcode::getZipcode() const
{


  return zipcode;

}

int main()
{
 Zipcode  zip;  // Create an instance of the class

  cout << zip.getZipcode() << endl;
}
You never call createZipcode, so zipcode is never initialized. One possible solution is to call that function in the constructor.
Topic archived. No new replies allowed.