Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

andrewheard

macrumors regular
Original poster
May 16, 2005
166
0
Ontario, Canada
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
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
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

C doesn't include a way to execute dynamically generated code, so you're better off leaving it as is.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.