Conditional expressions

Jun 6, 2013 at 11:54pm
i just wanted to double check if the code i wrote is right.i have to turn these conditional expression into if/else statements.

1
2
3
4
5
6
7
8
  total += count == 1 ? sales : count * sales


if(count==1)
  total=total+sales;
else
  total=total+count*sales;
Last edited on Jun 6, 2013 at 11:54pm
Jun 6, 2013 at 11:56pm
The both code snips correspond each other.
Jun 7, 2013 at 12:07am
Should be parentheses around the condition and end in a semicolon.

But it simplifies to
 
total += sales * count;
Jun 7, 2013 at 12:13am

@Chervil

Should be parentheses around the condition

There is no need to use parenthese around the condition.
Topic archived. No new replies allowed.