Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

The Ternary Operator ?: Solution

The Ternary Operator ?: Dersi Problem Çözümleri

Although it may make more sense to use an if-else statement in this exercise, the following program uses two ?: operators:

import std.stdio;

void main() {
    write("Please enter the net amount: ");

    int amount;
    readf(" %s", &amount);

    writeln("$",
            amount < 0 ? -amount : amount,
            amount < 0 ? " lost" : " gained");
}

The program prints "gained" even when the value is zero. Modify the program to print a message more appropriate for zero.