稍微改了一下
#include<stdio.h>
#include<math.h>
#include<process.h>
double num1,num2;
double add(double x,double y)
{
return x+y;
}
double cut(double x,double y)
{
return x-y;
}
double ride(double x,double y)
{
return x*y;
}
double Remov(double x,double y)
{
double z;
if(y==0) printf("eorro 除数不能为0\n");
z=x/y;
return z;
}
double (*p[4])(double,double)={add,cut,ride,Remov};//函数指针数组
void input()
{
system("cls");
printf("请你输入第一个数:");
scanf("%lf",&num1);
printf("请你输入第二个数:");
scanf("%lf",&num2);
return;
}
int main(int argc, char **argv)
{
int n;
do{
printf("\n");
printf("------计算系统--(ィ+ /厶 BY0.02)-----\n");
printf("=====================================\n");
printf(" 1. 加法运算\n\n");
printf(" 2. 减法运算\n\n");
printf(" 3. 乘法运算\n\n");
printf(" 4. 除法运算\n\n");
printf(" 5. 退出运算\n\n");
printf("=====================================\n");
printf("请选择(1~5):\n");
scanf("%d",&n);
if(n<=4&&n>=1)
{
input();
printf("结果是:%lf\t\n",p[n-1](num1,num2));
}
else if(n==5)
{
exit(0);
}else
{
system("cls");
printf("---ERROR----\n");
}
}while(n<=6);
system("pause");
return 0;
}
#include<stdio.h>
#include<math.h>
#include<process.h>
double num1,num2;
double add(double x,double y)
{
return x+y;
}
double cut(double x,double y)
{
return x-y;
}
double ride(double x,double y)
{
return x*y;
}
double Remov(double x,double y)
{
double z;
if(y==0) printf("eorro 除数不能为0\n");
z=x/y;
return z;
}
double (*p[4])(double,double)={add,cut,ride,Remov};//函数指针数组
void input()
{
system("cls");
printf("请你输入第一个数:");
scanf("%lf",&num1);
printf("请你输入第二个数:");
scanf("%lf",&num2);
return;
}
int main(int argc, char **argv)
{
int n;
do{
printf("\n");
printf("------计算系统--(ィ+ /厶 BY0.02)-----\n");
printf("=====================================\n");
printf(" 1. 加法运算\n\n");
printf(" 2. 减法运算\n\n");
printf(" 3. 乘法运算\n\n");
printf(" 4. 除法运算\n\n");
printf(" 5. 退出运算\n\n");
printf("=====================================\n");
printf("请选择(1~5):\n");
scanf("%d",&n);
if(n<=4&&n>=1)
{
input();
printf("结果是:%lf\t\n",p[n-1](num1,num2));
}
else if(n==5)
{
exit(0);
}else
{
system("cls");
printf("---ERROR----\n");
}
}while(n<=6);
system("pause");
return 0;
}