×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

EVEN AND ODD NUMBER PROGRAMMING

EVEN AND ODD NUMBER PROGRAMMING

EVEN AND ODD NUMBER PROGRAMMING

(OP)
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

RE: EVEN AND ODD NUMBER PROGRAMMING

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


RE: EVEN AND ODD NUMBER PROGRAMMING

(OP)
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

RE: EVEN AND ODD NUMBER PROGRAMMING

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources