|
From: Per W. <pw...@ia...> - 2003-09-24 03:32:30
|
The enum has nothing to do with it.
if ('u') ...
is the same as
if ('u' != 0) ...
so the expression will be
if (letter2 != 'u' || 1 || 1 || 1 || 1) ...
which reduces to
if (1) ...
which is obviously always true.
/Per W
On Wed, 24 Sep 2003, Nathan Stanley wrote:
> I'm not sure, but I think this depends on the type of 'letter2' in the if statement. Your example code showed: value letter
> I don't know if you meant letter2 there, but if so.. you are using an enum in your conditional, so this code would be working as expected.
>
> Someone more learned would know more about this.
> ----- Original Message -----
> From: -
> To: dev...@li...
> Sent: Wednesday, September 24, 2003 6:00 AM
> Subject: [Dev-C++] IF
>
>
> problem with if statement:
> if (letter2 != 'u' || 'v' || 's' || 't' || 'a') {
> cout<<"An error has occured, check you typed in only u, v, s, t or a."<<endl;
> exit();
> }
>
> Compiles ok but after checking i've realised it believes the values are part of an earlier enum declaration:
>
> enum value{u,v,s,t,a};
> value letter;
>
> How do i tell the compiler i want charactors, not enum values?
|