171k views
1 vote
Write a conditional expression that assign the value 0 to a credits variable if it is less than 0; otherwise the value of the credits variable remains unchanged.

2 Answers

3 votes

Answer:

credits = (credits < 0) ? 0 : credits;

Step-by-step explanation:

This is the ternary conditional operator.

User Oldbam
by
6.1k points
4 votes

Answer:

void updateCredit(float credit){

if credit < 0.0

credit = 0.0;

}

Step-by-step explanation:

I am going to write a C function for this.

The input is your credit value, and it has just a conditional to verify if it is not negative.

void updateCredit(float credit){

if credit < 0.0

credit = 0.0;

}

User Chris J Harris
by
6.5k points