Untitled

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

#define MAX_INPUT_LENGTH 100

// Function to evaluate the expression
double evaluate(char* expr) {
    char* end;
    double result = strtod(expr, &end);
    while (*end != '\0') {
        char op = *end++;
        double operand = strtod(end, &end);
        switch (op) {
            case '+': result += operand; break;
            case '-': result -= operand; break;
            case '*': result *= operand; break;
            case '/': result /= operand; break;
        }
    }
    return result;
}

// Main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    char input[MAX_INPUT_LENGTH];
    double result;
    HWND hwnd = GetConsoleWindow();
    ShowWindow(hwnd, nCmdShow);

    while (1) {
        // Get user input
        printf("Enter expression: ");
        fgets(input, MAX_INPUT_LENGTH, stdin);
        input[strcspn(input, "\n")] = '\0';

        // Evaluate expression
        result = evaluate(input);

        // Display result
        printf("Result: %.2f\n", result);
    }

    return 0;
}