0
votes

a bit of a C language noobie here. Either way, I've been working on this project for a while now, upon compiling it in Visual Studio 2010, it's producing errors, a bundle of them.

It says possible losses of data when using floats (Keep in mind the whole project is built upon floats).

Furthermore, this is the errors I am getting.

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

And This is my code

    #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;
}
1
There is a compilation error in result=(e1*e3-ne2)(e1*e1-ne4); line of inspect function.Vishal Gupta
For int to float conversion warning please refer stackoverflow.com/questions/7775129/….Vishal Gupta
How to fix the error then?Sulaiman AlOmar
on line 81 you forgot to use * in b/w braces result=(e1*e3-ne2)(e1*e1-ne4) And you did not define SLOPE function in your code. Rest of the things are just warning.Aadil Ahmad
Upon taking a close look, I was printing the "result" variable which is not even initialized whereas i needed to print res1 & res2.Sulaiman AlOmar

1 Answers

0
votes

Upon taking a close look, I was printing the "result" variable which is not even initialized whereas i needed to print res1 & res2. – Sulaiman AlOmar