Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

EVEN AND ODD NUMBER PROGRAMMING

Status
Not open for further replies.

allainmfg

Mechanical
Jan 15, 2007
20
I'm trying to program a line where I have a number and when this number is a even or odd number, the program changes. I'm looking for the fonction that will allow the program to change the pattern if x=2, 4, 6, 8, 10..... and will allow to change it again if x=1, 3, 5, 7, 9......
Like, I have

IF x 'fonction for even number'
pattern_1=2
else
pattern_1=3
endif

thanks
 
Replies continue below

Recommended for you

I think the function you are looking for is "integer division"

Integer division is division in which the fractional part (remainder) is discarded is called integer division and is sometimes denoted "\". Integer division can be defined as , where "/" denotes normal division and is the floor function. For example,

10 / 3 = 3 + .33333

so
10 \ 3 = 3

Then you must compare the two statements like this

if (10/3)-(10\3) <> 0
then
.....
else
.....
endif

Unfortunately, ProE does not have the "integer division" implemented, but you can simulate it using "floor" function:

if (10/3)-floor(10/3) <> 0 .....

-Hora


 
I'm not sure if this is gonna work for what I want to do.

I have a pattern of prt0001 and a pattern of prt0002 and I want that when the pattern of prt0001 is a even number that the pattern of prt0002 is equal to the pattern of prt0001 divided by 2 but when the pattern of prt0001 is a odd number, I want the pattern of prt0002 to be equal to the pattern of prt0001 divided by 2 + 1

IF PATTERN_PRT0001=EVEN NUMBER
PATTERN_PRT0002=PATTERN_PRT0001/2
ELSE
IF PATTERN_PRT0001=ODD NUMBER
PATTERN_PRT0002=(PATTERN_PRT0001/2)+1
ENDIF
ENDIF

THANKS
 
OK, I understand, then is very simple:

if ((-1)^PATTERN_PRT0001 == 1)
then
.....
else
....

endif

because:
(-1)^even number = +1 and (-1)^odd number = -1

That's all. Good luck

-Hora
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor