if statemet problem

  • Thread starter Thread starter tz
  • Start date Start date
T

tz

The statement below is resulting in this error:

C:\Documents and Settings\Teddy\My Documents\Visual Studio
Projects\Calendar\Calendar.cs(181): Operator '&&' cannot
be applied to operands of type 'int' and 'bool'

int mmonth,m;
if((mmonth = 1) && ((m > 1) && (m < 14)))

I tried to change the second argument to a bool and
received the same error.
What is going on? Does someone have suggestions please?
 
tz,

a good programming practive to avoid this type of typo is to use

if ( ( 1 == mmonth ) ...

instead.

This format will give a syntax error if you miss the second equals sign.
 
Beginner mistake.
thanks.
-----Original Message-----
tz,

a good programming practive to avoid this type of typo is to use

if ( ( 1 == mmonth ) ...

instead.

This format will give a syntax error if you miss the second equals sign.


--

Lynn Harrison
SHAMELESS PLUG - Introduction to 3D Game Engine Design (C# & DX9)
www.forums.Apress.com





.
 
Lynn Harrison said:
a good programming practive to avoid this type of typo is to use

if ( ( 1 == mmonth ) ...

instead.

Not in C#. Note that the OP was already getting a syntax error - it
wasn't compiling and managing to assign 1 to mmonth.
 
Lynn Harrison said:
tz,

a good programming practive to avoid this type of typo is to use

if ( ( 1 == mmonth ) ...

No, this is the kind of nonsense that you have to write in C and C++ because
the typing rules are too weak (lack of boolean type).

But you don't need to write it this way in C# because the C# compiler will
give you an error if you write if (mmonth = 1) instead of if (mmonth == 1).
So, the recommended way to write it in C# is: if (mmonth == 1)

Bruno.
 
Back
Top