how to print my information

in my c++ code i want show my zipcode when i run it I write like that but there is error said "getZipcode" was not declared in the scope i am sure my there is something wrong with my code and i can not find it please help me!
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();
    ~Zipcode();
    void createZipcode();
 
    int getZipcode() const;

private:
    int zipcode;
    
    int d;

};
Zipcode::Zipcode()
{
    zipcode = 0;
    correctionDigit = 0;
}
void Zipcode::createZipcode()
{
 zipcode = 1 + rand() % 9;
	for (int i = 1; i <= 4; i++)
	{
		d = rand() % 10;
		zipcode = 10 * zipcode + d;
	}
}
int Zipcode::getZipcode() const
{
    return (zipcode);
}


int main()
{

 cout<<getZipcode()<<endl;


}
Line 44: A function call of a class member must be relative to an instance of the class.

41
42
43
44
45
int main()
{  Zipcode  zip;  // Create an instance of the class

  cout << zip.getZipcode() << endl;
}

Last edited on
qingcheng wrote:
hey I changed my code as you told me to, and I try to run the code it show only "0" on the screen instead of a zipcode, can you point out which part is wrong with my zipcode ?


Did you call createZipcode() ?
 
  zip.createZipcode();

qingcheng wrote:
no i did not call it in my getzicode function how do i call my createzipcode function ?

I showed you exactly how to call it in my previous post.
Topic archived. No new replies allowed.