left of '->fullname' must point to... it does

When trying to compile, the following error appears:

(34) :error C2679: binary '!=' : no operator found which takes a right-hand operand of type 'char' (or there is no acceptable conversion)


Source:

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
#include <iostream>
#define ArSize 3
using namespace std;
void menu();
const int strsize = 30;
//Benevolent Order of Programmers name structure
struct bop
{
	char fullname[strsize];	//real name
	char title[strsize];	//job title
	char bopname[strsize];	//secret BOP name
	int preference;	//0 = fullname, 1 = title, 2 = bopname
};
int main()
{
	bop * pointer = new bop[ArSize];
	char choice;
	cout << "Firstly, populate the member database.\n\n"
			"++++++++++++++++++++++++++++++++++++++\n\n";
	for (int i = 0; i < ArSize; i++)
	{
		cout << "Enter full name:\n";
		cin.get(pointer[i]->fullname, strsize);
		cout << "Enter title name:\n";
		cin.get(pointer[i]->title, strsize);
		cout << "Enter BOP name:\n";
		cin.get(pointer[i]->bopname, strsize);
		cout << "Enter member's preference:\n";
		cin.get(pointer[i]->preference, strsize);
	}
	cout << "Message: Populating the member database completed.\n\n"
			"+++++++++++++++++++++++++++++++++++++++\n\n";
	menu();
	while (cin != 'q' $$ char(isalpha(choice)))
	{
	cin >> choice;
	switch(choice)
	{
	case a:
//display by name
		break;
	case b:
//display by title
		break;
	case c:
//display by bopname
		break;
	case d:
//display by preference
		break;
	default:
		cout << "Invalid choice. Try again.\n";
		break;
	}
	}
	cout << "Bye!\n";
	system("pause");
	return 0;
}

void menu()
{
	cout << "Benevolent Order of Programers Report\n"
			"a. display by name		b. display by title\n"
			"c. display by bopname	d. display by preference\n"
			"q. quit\n";
}
Last edited on
1. You have a ; after the for loop, remove it. //EDIT: poster has reedited his code before I posted this.
2. replace -> with . in lines 23, 25, 27.
3. On line 29 you're trying to read a string into an int.
4. Line 34: You can't compare cin (std::istream) to a char. You want to read a character into a char variable, and then compare if the variable is equal to 'q';
5. Line 39, 42, 45, 48 You wanna put the a,b,c,d, into ' ' .('a','b'....)
6. Don't use system("pause");
http://www.cplusplus.com/forum/articles/11153/
Use cin.ignore(numeric_limits<streamsize>::max(), '\n'); instead (you gonna need to #include <limits> .

That's for syntactic errors. I didn't checked for any logical errors.
Last edited on
'pointer' is a terrible name for a variable, btw. Why not name it 'bops' or something?

What type of thing is pointer[i]? Is it a bop* or a bop?

(Remember, . is member resolution for structures, and -> is member resolution for pointers to structures.)


Line 34: This line makes no sense:
 - cin will never be equal to 'q'.
 - $$ does not mean anything.
 - You are using choice before you get it from the user, on line 36.
 - isalpha() returns a boolean, not a char. Why are you casting it?

Case tags, lines 39, 42, 45, and 48: I think you mean case 'a':, etc.


I recommend that your menu() function be revised to perform the complete action of a menu:
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
char menu()                                                               
{
	char choice;

	// Display the menu
	cout << "Benevolent Order of Programmers Report\n"
		"  a. display by name     b. display by title\n"
		"  c. display by bopname  d. display by preference\n"
		"  q. quit\n"
		"> "
	     << flush;

	// Get the user's choice
	while (true)
	{
		cin >> choice;
		cin.ignore( 1000, '\n' );
		choice = tolower( choice );

		if (string("abcdq").find( choice ) != string::npos)
			break;

		cout << "What? " << flush;
	}

	return choice;
}

Now you can use it naturally:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
	bool done = false;                                                        
	while (!done)
	{
		switch (menu())
		{
		case 'a':
			// display by name
			break;
		case 'b':
			// display by title
			break;
		case 'c':
			// display by bopname
			break;
		case 'd':
			// display by preference
			break;
		case 'q':
			done = true;
		}
	}
	cout << "Bye!\n";
	return 0;

Hope this helps.
R0mai:
Thanks for info.

Duoas:
Will try it, thanks.

Will need to get accustomed to new things like "cin.ignore()", "flush" and "string::npos"
But it works perfectly.

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>

#define ArSize 3

using namespace std;

char menu();

const int strsize = 30;

//Benevolent Order of Programmers name structure
struct bop
{
	char fullname[strsize];	//real name
	char title[strsize];	//job title
	char bopname[strsize];	//secret BOP name
	int preference;	//0 = fullname, 1 = title, 2 = bopname
};

int main()
{
	bop * pointer = new bop[ArSize];

	cout << "Firstly, populate the member database.\n\n"
			"++++++++++++++++++++++++++++++++++++++\n\n";
	for (int i = 0; i < ArSize; i++)
	{
		cout << "Enter full name:\n";
		cin.get(pointer[i].fullname, strsize);
		cin.ignore();
		cout << "Enter title name:\n";
		cin.get(pointer[i].title, strsize);
		cin.ignore();
		cout << "Enter BOP name:\n";
		cin.get(pointer[i].bopname, strsize);
		cin.ignore();
		cout << "Enter member's preference:\n";
		cin >> pointer[i].preference;
		cin.ignore();
	}
	cout << "Message: Populating the member database completed.\n\n"
			"+++++++++++++++++++++++++++++++++++++++\n\n";

	bool done = false;
	while (!done)
	{
	switch(menu())
	{
	case 'a':
		for (int i = 0; i < ArSize; i++)
		{
			cout << pointer[i].fullname << endl;
		}
		break;
	case 'b':
		for (int i = 0; i < ArSize; i++)
		{
			cout << pointer[i].title << endl;
		}
		break;
	case 'c':
		for (int i = 0; i < ArSize; i++)
		{
			cout << pointer[i].bopname << endl;
		}
		break;
	case 'd':
		cout << "bop name list\n";
		break;
	case 'q':
		done = true;
		break;
	}
	}
	cout << "Bye!\n";
	system("pause");
	return 0;
}

char menu()                                                               
{
	char choice;

	// Display the menu
	cout << "Benevolent Order of Programmers Report\n"
		"  a. display by name     b. display by title\n"
		"  c. display by bopname  d. display by preference\n"
		"  q. quit\n"
		"> "
	     << flush;

	// Get the user's choice
	while (true)
	{
		cin >> choice;
		cin.ignore( 1000, '\n' );
		choice = tolower( choice );

		if (string("abcdq").find( choice ) != string::npos)
			break;

		cout << "What? " << flush;
	}

	return choice;
}
Last edited on
Topic archived. No new replies allowed.