185k views
5 votes
Write a statement that uses a conditional expression that determines if the credits variable is less than 0. If the condition is true, assign the value 0 to the credits variable, otherwise the value of the credits variable should remain unchanged.

User Szymon Rut
by
4.6k points

1 Answer

5 votes

Answer:

The statement and the expression is "credits = credits<0?0 : credits;" for the above question.

Step-by-step explanation:

  • The conditional expression is an expression that is used to determine the true and the false case. It works like the if and the else statement.
  • It has three parts which are shown above, in which the first part is to check the condition, the second part is excuted if the condition is true and the third part is executed if the condition is false. The variable is used to assign the value.
  • If any user provides the credit value and writes the above statement then the credit variable holds 0 for negative value and it holds the original value for any positive or zero value.
User TalMihr
by
4.2k points