首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

小弟我做的计算器 有几个警告 怎么办

2012-10-14 
【求助】我做的计算器 有几个警告 怎么处理啊/******计算器1.0 from Tony*********/#includestdio.h#inclu

【求助】我做的计算器 有几个警告 怎么处理啊
/******计算器1.0 from Tony*********/
#include<stdio.h>
#include<math.h>
//声明区
void Displaymenu(); //main menu 
double Add(double x,double y);  
double Sub(double x,double y);  
double Multi(double x,double y);
double Divide(double x,double y);
int Arith_compliment(int x,int y);
long int Factorial(int n);
int Sum_n(int n);

main()
{
  int choice;
  double tmp1,tmp2;
  double result;
  while(1)
  {
  Displaymenu(); 
  printf("\n 请选择您需要的计算类型:(1,2,3,4,5,6,7,8)?\n");
  scanf("%d",&choice);

  switch(choice)
  {
case 1:
  printf("please input two number to add:"); //加法
  scanf("%lf%lf",&tmp1,&tmp2);
  result=Add(tmp1,tmp2);
  printf("%g+%g=%g\n\n\n\n",tmp1,tmp2,result);
  break;
  case 2:
  printf("please input two number to sub:"); //减法
  scanf("%lf%lf",&tmp1,&tmp2);
  result=Sub(tmp1,tmp2);
  printf("%g-%g=%g\n\n\n\n",tmp1,tmp2,result);
  break;
  case 3:
  printf("please input two number to multi:"); //乘法
  scanf("%lf%lf",&tmp1,&tmp2);
  result=Multi(tmp1,tmp2);
  printf("%g*%g=%g\n\n\n\n",tmp1,tmp2,result);
  break;
  case 4:
  printf("please input two number to devide:"); //除法
  scanf("%lf%lf",&tmp1,&tmp2);
  result=Divide(tmp1,tmp2);
  printf("%g/%g=%g\n\n\n\n",tmp1,tmp2,result);
  break;
  case 5:
  printf("please input two number to arith compliment:"); //求余
  scanf("%lf%lf",&tmp1,&tmp2);
  result=Arith_compliment(tmp1,tmp2);
  printf("%g\n\n\n\n",result);
  break;
  case 6: //阶乘
  printf("please input a number to n!:");
  scanf("%lf",&tmp1);
  result= Factorial(tmp1);
  printf("%g\n\n\n\n",result);
  break;
  case 7:
  printf("please input a number to n:"); //累加
  scanf("%lf",&tmp1);
  result = (double)Sum_n((int)tmp1); 
  printf("0+..+%g=%g\n\n\n\n",tmp1,result);
  break;
  case 8:
  exit(0);
  default:
  printf("您输入的选项有误 请重新输入\n\n\n\n");

  }
  while (getchar()!='\n');
  }
}

//声明函数定义
//1
double Add(double x,double y)
{
return (x+y);
}

//2
double Sub(double x,double y)
{
return (x-y);
}
//3

double Multi(double x,double y)
{
return (x*y);
}
//4
double Divide(double x,double y)
{
if(y==0)
  {
printf("除数不可以为0\n\n\n\n");
  }
  else
{
return (x/y);
}
}
//5
int Arith_compliment(int x,int y)
{
if(y==0)
{
printf("除数不可以为0\n\n\n\n");
}
else
{
if(x<y)
{
printf("除数不可以大于被除数\n\n\n\n");
}
else
return x%y;
}
}
//6
long int Factorial(int n)


{
int z=1,i;
for(i=1;i<=n;i++)
{
z=z*i;
}
return z;
}
//7
int Sum_n(int n)
{
if(n<0)
{
printf("请输入大于0的数\n\n\n\n");
}
else
{
int z=0,i;
for(i=1;i<=n;i++)
{
z+=i;
}
return z;
}
}
//8
void Displaymenu()
{
printf("+++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("++ 计算器0.1 ++\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("++ 1.加法 ++\n");
printf("++ 2.减法 ++\n");
printf("++ 3.乘法 ++\n");
printf("++ 4.除法 ++\n");
printf("++ 5.求余 ++\n");
printf("++ 6.阶乘 ++\n");
printf("++ 7.累加 ++\n");
printf("++ 8.退出 ++\n");
printf("++ tony's program ++\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("+++++++++++++++++++++++++++++++++++++++++++++++\n");


























1>------ 已启动生成: 项目: 计算器, 配置: Debug Win32 ------
1>正在编译...
1>1.c
1>f:\vc\tony\000\计算器\1.c(23) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(29) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(35) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(41) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(47) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(53) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(54) : warning C4244: “函数”: 从“double”转换到“int”,可能丢失数据
1>f:\vc\tony\000\计算器\1.c(54) : warning C4244: “函数”: 从“double”转换到“int”,可能丢失数据
1>f:\vc\tony\000\计算器\1.c(59) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(60) : warning C4244: “函数”: 从“double”转换到“int”,可能丢失数据


1>f:\vc\tony\000\计算器\1.c(65) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : 参见“scanf”的声明
1>f:\vc\tony\000\计算器\1.c(70) : warning C4013: “exit”未定义;假设外部返回 int
1>f:\vc\tony\000\计算器\1.c(108) : warning C4715: “Divide”: 不是所有的控件路径都返回值
1>f:\vc\tony\000\计算器\1.c(125) : warning C4715: “Arith_compliment”: 不是所有的控件路径都返回值
1>f:\vc\tony\000\计算器\1.c(152) : warning C4715: “Sum_n”: 不是所有的控件路径都返回值
1>生成日志保存在“file://f:\vc\tony\000\计算器\Debug\BuildLog.htm”
1>计算器 - 0 个错误,15 个警告

[解决办法]

C/C++ code
[code=C/C++]double Divide(double x,double y){if(y==0)    {printf("除数不可以为0\n\n\n\n");    }    else{return (x/y);}}
[解决办法]
result=Arith_compliment(tmp1,tmp2); int Arith_compliment(int x,int y) 
double tmp1,tmp2; 类型不匹配。都是,自己查。

没别的错误,可以结了。

[解决办法]
[Quote=引用:]
C/C++ code
C/C++ code
double Divide(double x,double y){if(y==0)    {printf("除数不可以为0\n\n\n\n");    }else{return (x/y);}}int Arith_compliment(int x,int y){if(y==0){printf("除数不可以为0\n\n\n\n");}else{if(x <y){printf("除数不可以大于被除数\n\n\n\n");}elsereturn x%y;}}
[解决办法]
scanf_s用这就可以了

热点排行