warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence

I keep getting the error warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence

when I try to run my program, it is to do with this function when I am trying to pass a string to see if it equals A,F,M OR V.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

validateMake(hdl,33,11,cars[size].make,"\tMake must be A, F, M or V.");

  void validateMake(HANDLE hdl, int x, int y, char str, char errmessage[])
{
	bool ok = true;

	do
	{
		gotoXY(hdl,x,y); cin.get(str,'\n');cin.ignore(10,'\n');

		if(str != 'A' & str != 'F' & str != 'M' & str != 'V')
			message(hdl, errmessage,5,25);

	}while(str != 'A' & str != 'F' & str != 'M' & str != 'V');

}
Last edited on
&& is logical AND (that is what you wantr here)

& is bitwise AND

http://www.cplusplus.com/doc/tutorial/operators/
Maybe this was not the problem, this is a red line underneath the dot in cin.get

the error is:
error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'char' to 'char *


I have a populated array and I am trying to validate a new entry into the array by doing this:

validateMake(hdl,33,11,cars[size].make,"\tMake must be A (Audi), F (Ford), M (Mercedes) or V (VolksWagon).");


Last edited on
> Maybe this was not the problem,

No, that was definitely a problem.


> this is a red line underneath the dot in cin.get

Yes, that too is a problem.
The somewhat unintutively named 'str' is actually a char.

1
2
// cin.get(str,'\n') ;
cin.get(str) ;

it is now saying error
C2664: 'validateMake' : cannot convert parameter 4 from 'char' to 'char []'


I have it set as char make within a struct, would this have anything to do with it?

are you sure it's a char and not char[] or char*

Thank you very much guys, when I called the function at the beginning I still had char str[] instead of char str.

BEFORE:
void validateMake(HANDLE hdl, int x, int y, char str[], char errmessage[]);


AFTER:
void validateMake(HANDLE hdl, int x, int y, char str, char errmessage[]);
Topic archived. No new replies allowed.