大家觉得我做的这个计算器怎样?我才初二,别批得太狠了。
大家觉得我做的这个计算器怎样?我才初二,别批得太狠了。#include "stdio.h"
#include "math.h"
#include "string.h"
double jia()
{
double s,x,y;
printf("输入两个加数\n");
scanf("%le%le",&x,&y);
s=x+y;
printf("%le+%le=%le\n",x,y,s);
return 0;
}
double jian()
{
double s,x,y;
printf("输入被减数,减数\n");
scanf("%le%le",&x,&y);
s=x-y;
printf("%le-%le=%le\n",x,y,s);
return 0;
}
double cheng()
{
double x,y,z;
printf("输入乘数\n");
scanf("%le%le",&x,&y);
z=x*y;
printf("%le*%le=%le\n",x,y,z);
return 0;
}
double chu()
{
double x,y,z;
printf("输入被除数,除数\n");
scanf("%le%le",&x,&y);
printf("%le/%le=%le\n",x,y,x/y);
return 0;
}
main()
{
char ch[50];
int n;
printf("==========开始==========\n你可以输入help来查询指令\n");
for (n=0;n<=30000;n++)
{
gets(ch);
if (strcmp(ch,"结束")==0)break;
if (strcmp(ch,"加")==0)jia();
if (strcmp(ch,"减")==0)jian();
if (strcmp(ch,"乘")==0)cheng();
if (strcmp(ch,"除")==0)chu();
if (strcmp(ch,"help")==0)help();
}
printf("==========结束==========\n");
}
help()
{
printf("输入加,进行加法运算\n");
printf("输入减,进行减法运算\n");
printf("输入结束,结束程序\n");
return 0;
}