// 5. Arithmetic calculator (add, subtract, multiply, divide, modulus)
//    using switch-case
#include <stdio.h>

int main() {
    int a, b;
    char op;

    printf("Enter first number: ");
    scanf("%d", &a);
    printf("Enter operator (+ - * / %%): ");
    scanf(" %c", &op);   // space before %c skips the leftover Enter key
    printf("Enter second number: ");
    scanf("%d", &b);

    switch (op) {
    case '+':
        printf("%d + %d = %d\n", a, b, a + b);
        break;
    case '-':
        printf("%d - %d = %d\n", a, b, a - b);
        break;
    case '*':
        printf("%d * %d = %d\n", a, b, a * b);
        break;
    case '/':
        if (b == 0)
            printf("Error: division by zero\n");
        else
            printf("%d / %d = %.2f\n", a, b, (float)a / b);
        break;
    case '%':
        if (b == 0)
            printf("Error: modulus by zero\n");
        else
            printf("%d %% %d = %d\n", a, b, a % b);
        break;
    default:
        printf("Invalid operator\n");
    }

    return 0;
}
