Using a variable as an operator

Discussion in 'Mac Programming' started by andrewheard, Jan 28, 2008.

  1. macrumors regular

    Joined:
    May 16, 2005
    Location:
    Ontario, Canada
    #1
    Hi,
    I wrote a little C program for my programming class and it asks the user what operation they would like to perform (+, -, /, *, %). I currently just have if statements that say if its + then value1 + value2, etc. Is it possible to use the variable as an operator so I don't need all the if statements or am I better off leaving it as is?

    Thanks for your time,

    Andrew
     
  2. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    C doesn't include a way to execute dynamically generated code, so you're better off leaving it as is.
     
  3. thread starter macrumors regular

    Joined:
    May 16, 2005
    Location:
    Ontario, Canada
    #3
    Sounds good. Makes my life easy.
     

Share This Page