classes & constructors

In this class I have created a constructor...I call one member function (customer) in a another function (screen)...but the default value is displaying...to be more specific my default for user is "bookie"... but I call the member function customer to changer user to a name as in Taylor, or billy. why is the default displaying? user

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 <cmath>
#include <string>
using namespace std;



class BLUEBOX {
private:
	std::string user, ID, Admin, Billy, Edward, Taylor;
public:
	BLUEBOX ();
	BLUEBOX (std::string, std::string);
	
void inventory();
void sales();
void screen();
void customers(string ID);
void returned();
void admin(); 

};

BLUEBOX::BLUEBOX(){
user = "bookie";
ID = "tookie";
screen();
}
BLUEBOX::BLUEBOX(std::string j,std::string k){
user = j;
ID = k;
}

void BLUEBOX::screen(){
//------MAIN SCREEN--------
cout << "BlueBox DVD rental"<<endl;
cout << "Please enter your user ID ";

cin >> ID;
customers(user);
cout << "Welcome to the BlueBox DVD rental" << user << endl;

system("pause");
	return;}

void BLUEBOX::customers(string j){



 if (ID == "00")
  j = Billy;
 
 else if (ID == "01") j = Edward;
 
 else if (ID == "12")
 j = Taylor;

 else if (ID == "99") j = Admin ;


 
	return;}
Last edited on
So through the constructor you call these functions to initialize the data of the new BLUEBOX object?

They enter a value into ID, but you call the customers function with user? Aren't they going to be entering the 00, 01 etc. so that you can assign a value to user? I think you'd want to send what they enter in ID here.

1
2
cin >> ID;
customers(user);


Then check if j == "00" etc., not ID? j is a copy of the value you sent in. Then set user, not j, to "Billy" or "Taylor", not Billy or Taylor?

1
2
3
4
5
6
7
8
9
10
11
12
13
void BLUEBOX::customers(string j){

 if (ID == "00")
  j = Billy;
 
 else if (ID == "01") j = Edward;
 
 else if (ID == "12")
 j = Taylor;

 else if (ID == "99") j = Admin ;

return;}


Are Admin, Billy, Edward, Taylor just examples of usernames? Here they are variable names with no initialized value.
1
2
private:
	std::string user, ID, Admin, Billy, Edward, Taylor;
Topic archived. No new replies allowed.