VC编制程序,实现类似于windows的科学计算器,我这个哪里错了

2025-01-05 03:34:34
推荐回答(2个)
回答1:

因为你的科学计算那块的 ch的数据类型定义错了,应该是 char 你给写成了 int
还有,这个ch你在前面已经定义过了,不能重复定义,否则会报错,此处不需要进行定义...

回答2:

错的地方实在不少,例如简易计算器无数据输入,return 错用位置等,无法一一例举,程序已修改,没实际运行,在程序前几行加了一行
do while(ch=getchar()=='x')
以此来实现计算器循环使用及按x键退出程序功能
满意请及时采纳,谢谢

#include
#include
#include
#include
int main()
{
char ch;
double x,y;
double s;
printf("j=简易型,k=科学型,x=退出\n");
do while(ch=getchar()=='x')
{
if (ch=='j')
{
printf("a=加法,s=减法,m=乘法,d=除法,r=向上,x=退出\n");
scanf("%c",&ch);
switch(ch)
{
case 'a':printf("输入x y\n");scanf("%lf %lf",&x,&y);printf("%lf+%lf=%lf\n",x,y,x+y);break;
case 's':printf("输入x y\n");scanf("%lf %lf",&x,&y);printf("%lf+%lf=%lf\n",x,y,x-y);break;
case 'm':printf("输入x y\n");scanf("%lf %lf",&x,&y);printf("%lf+%lf=%lf\n",x,y,x*y);break;
case 'd':printf("输入x y\n");scanf("%lf %lf",&x,&y);printf("%lf+%lf=%lf\n",x,y,x/y);break;
case 'r':break;
case 'x':exit(0);
default :printf("error\n");
}

}
else if (ch=='k')
{
printf("i=正弦,c=余弦,t=正切,m=x^y,e=ln,s=log,j=x!,d=1/x,u=x^3,p=x^2,r=向上,x=退出\n");
scanf("%c",&ch);
switch(ch)
{
case 'i':printf("输入x\n");scanf("%lf",&x);printf("sin(%lf)=\t%lf\n",x,sin(x));break;
case 'c':printf("输入x\n");scanf("%lf",&x);printf("cos(%lf)=\t%lf\n",x,cos(x));break;
case 't':printf("输入x\n");scanf("%lf",&x);printf("tan(%lf)=\t%lf\n",x,tan(x));break;
case 'm':printf("输入x y\n");scanf("%lf %lf",&x,&y);printf("%lf^(%lf)=\t%lf\n",x,y,pow(x,y));break;
case 'e':printf("输入x\n");scanf("%lf",&x);printf("ln(%lf)=\t%lf\n",x,log(x));break;
case 's':printf("输入x\n");scanf("%lf",&x);printf("log10(%lf)=\t%lf\n",x,log10(x));break;
case 'j':printf("输入x\n");scanf("%lf",&x);s=1;for(int i=1;i case 'd':printf("输入x\n");scanf("%lf",&x);printf("1/%lf=\t%lf\n",x,1/x);break;
case 'u':printf("输入x\n");scanf("%lf",&x);printf("%lf^3=\t%lf\n",x,x*x*x);break;
case 'p':printf("输入x\n");scanf("%lf",&x);printf("%lf^2=\t%lf\n",x,x*x);break;
case 'r':break;
case 'x':exit(0);
default :printf("error\n");
}
}
}
exit(0);
}