is not a member

hello , i have this problem with my code and i cant really figure it out !


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
#include<iostream.h>
#include<string.h>
#include<conio.h>

class customer{
int no,nb,per;
char name[20];
public:

customer(char *cname,int cno , int cnb,int cper){
strcpy(name,cname);
no=cno;
nb=cnb;
cper=per;
}
customer(){};
void borrow(customer C ){
if (C.nb <3 && C.per>7){
cout<<"yes";}
else cout<<"No";
}};

void main(){
customer c1;
cin>>c1.cnb>>c1.cper ;
c1.borrow;
getch();
}


it keeps saying that the
cnb and the cper are not members in the void main
and when i change them to nb and per its says they are not accessible

i just want to enter them from the void
can someone help ?
All data members of your class

class customer{
int no,nb,per;
char name[20];

has the private access control. So they are inaccessible outside the class and its member functions.

Also there is no indeed such data member as cnb in your class. cnb was declared as a parameter of a member function

customer(char *cname,int cno , int cnb,int cper );

but it does not mean that it is a member of the class.:)
Last edited on
the thing is
all data members should be private as declared in the question
so i have no idea what im doing
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
#include<iostream.h>
#include<string.h>
#include<conio.h>

class customer{
int no,nb,per;
char name[20];
public:
 customer(char *cname,int cno , int cnb ,int cper){
strcpy(name,cname);
no=cno;
nb=cnb;
cper=per;
}


void borrow(customer C ){
if ((C.nb <3) &&( C.per>7)){
cout<<"yes";}
else cout<<"No";
}};

void main(){
char name[20]  ;
int no,nb,per;
 cout<<"name:";
 cin>>name;
 cout<<"no";
 cin>>no;
 cout<<"nb";
 cin>>nb;
 cout<<"per;";
 cin>>per;
 customer c1(name,no,nb,per);
 c1.borrow(c1);
getch();
}


at least this one runs .
but it wont make sure of the if statment .. it goes to no even thou i want it yes
Topic archived. No new replies allowed.