if else statements

I'm editing a member function for a class. and I cant seem to figure out why there is an error in my statements. The "==" as in (ID == 00) is being underlined as if it's an error

1
2
3
4
5
6
7
8
9
10
11
  void BLUEBOX::customers(){
string Billy, Edward, Taylor;
 if (ID == 00)
 { user = Billy;
 }
 else if (ID == 01) { user = Edward;
 }
 else 
 {
	 user = Taylor;
}
here is the error when I debug
"1>Final.cpp(50): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)"
What type is ID? Sounds like it could be a string, and you're comparing it to a possible int, or maybe you intend for 00 to be a string, in which case you'll need quotation marks.
ID will be the user ID 00, 01, and 12. Once the user puts in their ID I want to welcome them by using their name...Here is the whole code....

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79


#include <iostream>
#include <cmath>
#include <string>
using namespace std;



class BLUEBOX {
private:
	std::string user, ID, Billy, Edward, Taylor, admin;
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();
cout << "Welcome to the BlueBox DVD rental" << user;

system("pause");
	return;}

void BLUEBOX::customers(string ID){

 if (ID == 00)
 user = Billy;
 
 else if (ID == 01) user = Edward;
 
 else if (ID == 12)
 user = Taylor;
 else 
user = admin;

 
	return;}
void BLUEBOX::inventory(){


return;}

void BLUEBOX::sales(){
	return;}


void BLUEBOX::returned(){
	return;}
void BLUEBOX::admin(){
return;}

int main(){
  BLUEBOX movies;

  system("pause");
	return 0;}
Try this:
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <cmath>
#include <string>
using namespace std;



class BLUEBOX {
private:
	std::string user, ID, Billy, Edward, Taylor, admin;
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();
cout << "Welcome to the BlueBox DVD rental" << user;

system("pause");
	return;}

void BLUEBOX::customers(string ID){

 if (ID == "00") ///Notice how the numbers are now in quotations
 user = Billy;
 
 else if (ID == "01") user = Edward; ///Notice how the numbers are now in quotations
 
 else if (ID == "12") ///Notice how the numbers are now in quotations
 user = Taylor;
 else 
user = admin;

 
	return;}
void BLUEBOX::inventory(){


return;}

void BLUEBOX::sales(){
	return;}


void BLUEBOX::returned(){
	return;}
void BLUEBOX::admin(){
return;}

int main(){
  BLUEBOX movies;

  system("pause");
	return 0;}
Last edited on
when I cout user in the main member function, it displays my default for user (in my constructor)...how to I get the names to display.
1
2
3
4
5
BLUEBOX::BLUEBOX(){
user = "bookie";
ID = "tookie";
screen();
}

is the default constructor, and will assign constant string values to user and ID

To add user and Id use the second constructor and pass the values to it:

1
2
3
4
BLUEBOX::BLUEBOX(std::string j,std::string k){
user = j;
ID = k;
}


if you intiate object with this:

movies ("myname", "MyId")

those values will be assigned to the members of BLUEBOX.

You may have to break up this class into different ones if you want to track movies, inventory, etc. . . you don't need user names as movie parameters, and you don't need to display the main screen at every instance of the class, for example. Just saying.
Topic archived. No new replies allowed.