Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
940 B
1
Indexable
Never
#include <stdio.h>
#include <windows.h>

int main() {
    int num1, num2, result;
    char operator;

    // Get input from user
    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("Enter operator (+, -, *, /): ");
    scanf(" %c", &operator);

    printf("Enter second number: ");
    scanf("%d", &num2);

    // Perform calculation based on operator
    switch (operator) {
        case '+':
            result = num1 + num2;
            break;
        case '-':
            result = num1 - num2;
            break;
        case '*':
            result = num1 * num2;
            break;
        case '/':
            result = num1 / num2;
            break;
        default:
            printf("Invalid operator");
            return 0;
    }

    // Display result in a message box
    char message[50];
    sprintf(message, "Result: %d", result);
    MessageBox(NULL, message, "Calculator", MB_OK);

    return 0;
}