【发布时间】:2015-01-09 06:52:49
【问题描述】:
这里有点 C 语言新手。不管怎样,我已经在这个项目上工作了一段时间,在 Visual Studio 2010 中编译它时,它会产生错误,它们是一堆错误。
它表示使用浮点数时可能会丢失数据(请记住,整个项目都是基于浮点数构建的)。
此外,这是我得到的错误。
1>----- 构建开始:项目:项目,配置:调试 Win32 ------ 1> 项目.c 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(44): 警告 C4996: 'scanf': 这个函数或变量可能不安全。考虑改用 scanf_s。要禁用弃用,请使用 _CRT_SECURE_NO_WARNINGS。详细信息请参见在线帮助。 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) :参见“scanf”的声明 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(55): 警告 C4013: 'system' undefined;假设 extern 返回 int 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(29):警告 C4101:'y':未引用的局部变量 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(77): 警告 C4244: '=' : 从 'int' 转换为 'float',可能丢失数据 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(78): 警告 C4244: '=' : 从 'int' 转换为 'float',可能丢失数据 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(79): 警告 C4244: '=' : 从 'int' 转换为 'float',可能丢失数据 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(80): 警告 C4244: '=' : 从 'int' 转换为 'float',可能丢失数据 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(81): 呃
这是我的代码
#include <stdio.h>
void table();
float inspect();
float calculation(float x1, float x2, float x3);
float SLOPE();
//time, **t is for time**
int t1=0;
int t2 = 1;
int t3 = 2;
int t4 = 3;
int t5 = 4;
int t6 = 5;
//Tempreture **h is for heat**
int h1=20;
int h2=36;
int h3=61;
int h4=68;
int h5=77;
int h6=110;
int n=6;
int main()
{
float m;
float b;
float y,x;
float res2;
float res1;
float result;
table();
m=SLOPE();
b=inspect();
res1=calculation(b,m,1.5);
printf("The temperture int TIME 1.5=%f\n",result);
res2=calculation(b,m,4.5);
printf("The temperture int time at 4.5 = %f\n", result);
printf("Please enter the time values you require");
scanf("%f",&x);
if (x>0)
{
result=calculation(b,m,x);
printf("The temperture value is: %f",result);
}
else
printf("**ERROR**");
system("pause");
return 0;
}
void table()
{
printf("Time Tempreture\n");
printf("%d %d\n",t1,h1);
printf("%d %d\n",t2,h2);
printf("%d %d\n",t3,h3);
printf("%d %d\n",t4,h4);
printf("%d %d\n",t5,h5);
printf("%d %d\n",t6,h6);
}
float inspect()
{
float result;
float e1,e2,e3,e4;
e1=t1+t2+t3+t4+t5+t6;
e2=t1*h1+t2*h2+t3*h3+t4*h4+t5*h5+t6*h6;
e3=h1+h2+h3+h4+h5+h6;
e4=t1*t1+t2*t2+t3*t3+t4*t4+t5*t5+t6*t6;
result=(e1*e3-n*e2)(e1*e1-n*e4);
return result;
}
float calculation(float x1,float x2, float x3)
{
float y;
y=x2*x3+x1;
return y;
}
【问题讨论】:
-
在result=(e1*e3-ne2)(e1*e1-ne4)中有编译错误;检查函数的行。
-
对于int到float的转换警告请参考stackoverflow.com/questions/7775129/…。
-
如何解决这个错误?
-
在第 81 行,您忘记在黑白大括号中使用 * 结果=(e1*e3-ne2)(e1*e1-ne4) 而您没有在代码中定义 SLOPE 函数。其余的只是警告。
-
仔细查看后,我正在打印“结果”变量,该变量甚至没有初始化,而我需要打印 res1 和 res2。
标签: c visual-studio-2010 visual-studio visual-studio-2012 project