#include <stdio.h>
#include <stdlib.h>
int num;
char fuhao;
void getnum_fuhao() {
num = 0;
char temp;
while(true) {
temp = getchar();
if('0' <= temp && temp <= '9') {
num *= 10;
num += (temp - '0');
}
else if(temp == ' ' || temp == '\n') continue;
else break;
}
fuhao = temp;
}
double input;
void getinput_fuhao() {
getnum_fuhao();
if(fuhao != '.') input = num;
else {
int num_before_point = num;
getnum_fuhao();
input = num;
while(input >= 1) {
input /= 10;
}
input += num_before_point;
}
//printf("input:%lf\n", input);
}
int main()
{
double result;
char op;
while(true) {
while(true) {
getinput_fuhao();
//printf("result:%lf\n", result);
//printf("op:%c\n", op);
switch(op) {
case '+': result += input; break;
case '-': result -= input; break;
case '*': result *= input; break;
case '/':
if(input == 0) printf("除数不能为零!");
else result /= input;
}
if(fuhao == '=') {
printf("%lf\n", result);
break;
}
if(fuhao == 'a' || fuhao == 'A') {
result = 0;
op = '+';
break;
}
if(fuhao == 'c' || fuhao == 'C') {
system("cls");
result = 0;
op = '+';
break;
}
op = fuhao;
}
}
return 0;
}
|