Conditional expressions

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
The both code snips correspond each other.
Should be parentheses around the condition and end in a semicolon.

But it simplifies to
 
total += sales * count;

@Chervil

Should be parentheses around the condition

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