
1条回答 默认 最新
Soda Wang 2021-09-28 11:22关注这是大致的代码框架,希望可以帮到你
#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; }这里只写了加法功能,其他运算和容错功能需要你自己实现
解决 无用评论 打赏 举报