40 ms·
Here's the code in either C or C#: return ( (price > 100) ? 10 : 5); Computer languages are for people. It should really be more like this: # # Desc
by wildgift 13y ago
Here's the code in either C or C#:
return ( (price > 100) ? 10 : 5);
Computer languages are for people. It should really be more like this:
#
# Description of what this does.
#
PRICE-THRESHOLD = 100
LOWER-PRICE = 5
UPPER-PRICE = 10
IF PRICE > PRICE-THRESHOLD RETURN UPPER-PRICE
ELSE RETURN LOWER-PRICE
Alternatively, use Excel:
=IF( (price > 100), 10, 5 )
Excel is cryptic, but a lot of finance people understand it.
- J_Darnley 13y agoWith C it can be more like what you want. Stop using ?: if you don't like it. if (price > 100) return 10; else return 5; Replace with more named variables if you want.
- the_af 13y agoI'm going to guess wildgift was being sarcastic. COBOL syntax is so needlessly verbose it interferes with the understanding of the actual formula. I contend that return price > 100 ? 10 : 5; is way more readable.
- nkoren 13y agoThat code works in C, C#, and JavaScript.
- weatherlight 13y agoruby too!