basics · beginner · ~15 min

Program status code

Model exit-code conventions.

Challenge

Model the exit-code convention: 0 means success, non-zero means failure.

Task

Implement int program_status(int errors) that returns the status code a program would exit with: 0 when errors is 0, otherwise 1. No main — the grader calls it.

Input

A single int errors (a count of errors, >= 0).

Output

Returns 0 if errors is 0, otherwise 1.

Example

program_status(0)   ->   0     (success)
program_status(1)   ->   1     (failure)
program_status(5)   ->   1

Edge cases

  • Any non-zero error count maps to 1, not to the count itself.

Input format

A single int errors (>= 0).

Output format

0 when errors is 0, otherwise 1.

Starter code

int program_status(int errors) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.