gpt4 book ai didi

计算温度项目,产生误差

转载 作者:行者123 更新时间:2023-11-30 17:26:06 26 4
gpt4 key购买 nike

这里有点 C 语言新手。不管怎样,我已经在这个项目上工作了一段时间了,在 Visual Studio 2010 中编译它时,它产生了一堆错误。

它表示使用 float 时可能会丢失数据(请记住整个项目都是基于 float 的)。

此外,这是我遇到的错误。

1>------ Build started: Project: Project, Configuration: Debug Win32 ------ 1> project.c 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(44): 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> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf' 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(55): warning C4013: 'system' undefined; assuming extern returning int 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(29): warning C4101: 'y' : unreferenced local variable 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(77): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(78): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(79): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(80): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data 1>c:\users\suliman\documents\visual studio 2010\projects\project\project\project.c(81): er

这是我的代码

    #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;
}

最佳答案

仔细一看,我正在打印“结果”变量,该变量甚至没有初始化,而我需要打印 res1 和 res2。 – 苏莱曼·阿尔奥马尔

关于计算温度项目,产生误差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26886659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com