按要求用c语言设计计算器小程序(vs2019)

img

这是大致的代码框架,希望可以帮到你

#include<conio.h>
#include<stdio.h>

int main()
{
    char ch, op = '!';
    int num1 = 0, num2 = 0;
    while (1) {
        ch = _getch();
        printf("%c", ch);
        if (ch >= '0' && ch <= '9') {
            if (op == '!') {
                num1 = num1 * 10 + (ch - '0');
            }
            else {
                num2 = num2 * 10 + (ch - '0');
            }
        }
        else if (ch == '+'
            || ch == '-'
            || ch == '*'
            || ch == '/') {
            op = ch;
        }

        else if (ch == '\n' || ch == '=') {
            break;
        }

        else {
            continue;
        }
    }

    switch (op)
    {
    case '+':
        printf("%d\n", num1 + num2);
        break;
    default:
        break;
    }

    return 0;
}

这里只写了加法功能,其他运算和容错功能需要你自己实现