Kodewick
Start learning →
Basic←→0 / 50

Simple calculator

#006Basiccase '-':5 min

Write a small calculator calc(a, op, b): op is one of '+', '-', '*', '/', and you return the result of a op b. For example, calc(6, '/', 4) is 1.5. For any other sign, return 0. When dividing, b is never 0.

Examples
calc(3, '+', 5)→8.0
calc(6, '/', 4)→1.5
The functiondouble calc(double a, char op, double b)
main.c
double calc(double a, char op, double b) {
    double r = 0;
    switch (op) {
        case '+': r = a + b; break;
        // your code here: the cases for minus, times and divide, each with break
    }
    return r;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.