C - Double bursting size

1

I am doing an IQA (Water Quality Index) exercise where I need to conduct a series of accounts. I created the functions and everything but always the result always comes out the way it is in the image, I have already tested the isolated function and the result is. Thanks for the help.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/****************************************************************************
*OX  - Oxigênio Dissolvido                                                  *
*CF  - Coliformes Fecais                                                    *
*ph  - Potencial Hidrogeniônico                                             *
*dbo - Demanda Bioquimica de Oxigênio (DBO = 5,20)                          *
*nt  - Nitrogênio Total                                                     *
*ft  - Fosforo Total                                                        *
*st  -                                                                      *
*dt  -                                                                      *
*    - Temperatura                                                          *
*****************************************************************************
*sg - soma geral das variavels acima (verificar utilidade)                  *
*produtorio - fatorial de cada elemento (verificar utilidade)               *
*****************************************************************************/

/************************************************
*                                               *
*           Começo das funções                  *
*                                               *
************************************************/

double q1 (double index) // Coliformes fecais
{
    double a = 98.03, b = -36.45, c = 3.138, d = 0.06776;

    printf("Parametro para Coliformes Fecais\n");
    if (index > 1e5) return 3.0;

    index = a + (b * (log(index))) + (c * pow((log10(index)), 2)) + (d * pow((log10(index)), 3));

    return index;
}
double q2 (double index) // Potencial Hidrogeniônico
{
    double a = 0.05421, b = 1.23, c = -0.09873;

    printf("Parametro de pH\n");
    if ( index >= 12) return 3.0;
    if ( index <= 2) return 2.0;

    index = a * pow(index, ((b * index) - (c * pow(index,2)))) + 5.231;

    return index;
}
double q3 (double index) // Demanda Bioquimica de Oxigenio
{
    double a = 102.6, b = -0.01101;

    printf("Demanda Bioquimica de Oxigênio\n");
    if ( index > 30 ) return 2.0;

    index = a * exp(b*index );

    return index;
}
double q4 (double index) // Nitrogenio Total
{
    double a = 98.96, b = -0.2232, c = -0.006457;

    printf("Nitrogenio total\n");
    if ( index > 90 ) return 1.0;

    index = a * pow(index, (b + (c * index)));

    return index;
}
double q5 (double index) // Fosforo Total
{
    double a = 213.7, b = -1.680, c = 0.3325;

    printf("Fosforo\n");
    if ( index > 10.0 ) return 5.0;

    index = a * exp(b * pow(index, c));

    return index;
}
double q6 (double index) // Temperatura
{
    double a = 0.0003869, b = 0.1815, c = 0.01081;

    printf("Temperatura\n");
    if ( index <= -5) return 1;
    if ( index > 15) return 9;

    index = 1 / (a*pow(index + b, 2)+c);

    return index;
}
double q7 (double index) // Turbidez
{
    double a = 97.34, b = -0.0139, c = -0.04917;

    printf("Turbidez\n");
    if ( index > 100) return 5.0;

    index = a*exp((b*index)+(c*sqrt(index )));
}
double q8 (double index) // Sólidos totais
{
    double a = 80.26, b = -0.00107, c = 0.03009, d = -0.1185;

    printf("Solidos\n");
    if ( index > 500 ) return 30.0;

    index = (a*exp((b*index) + (c*sqrt(index)))) + (d*index);
}
double q9 (double index) // Oxigênio dissolvido
{
    double a = 100.8, b = -106.0, c = -3745.0;

    printf("Oxigenio\n");
    if ( index > 140.0 ) return 47;

    index = a * exp (pow((index + b), 2)/ c);

    return index;
}

typedef double (*func) (double);

int main (void)
{
    double parametros;
    double iqa = 1;
    int i;

    func funcao[9] = {q1, q2, q3, q4, q5, q6, q7, q8, q9};
    double peso[9] = {0.15, 0.12, 0.10, 0.10, 0.10, 0.10, 0.08, 0.08, 0.17};

    // Função q7 com problema, ajustar
    for (i=0; i<7; i++)
    {
        scanf("%lf", &parametros);
        iqa *= pow(funcao[i](parametros), peso[i]);
        printf("Peso : %lf\n", peso[i]);
    }

    printf("IQA = %lf\n", iqa);
}

/****************************
*                           *
*          TESTE F7         *
*                           *
****************************/

/*#include <stdio.h>
#include <math.h>

int main(void)
{
    double index;
    double a = 97.34, b = -0.0139, c = -0.04917;

    printf("Turbidez\n");
    scanf("%lf", &index);
    if ( index > 100) return 5.0;

    index = a * exp ((b*index)+(c*sqrt(index )));

    printf("Index = %lf\n", index);
    return 0;
}*/
    
asked by anonymous 14.06.2016 / 22:43

1 answer

2

The functions q7() and q8() do not have return !

double q7 (double index) // Turbidez
{
    double a = 97.34, b = -0.0139, c = -0.04917;

    printf("Turbidez\n");
    if ( index > 100) return 5.0;

    index = a*exp((b*index)+(c*sqrt(index )));
    return index;                               // <== faltava return
}

Always compile with the maximum warnings from your compiler and pay attention to these warnings.

pt135022.c:102:1: warning: control may reach end of non-void function
      [-Wreturn-type]
}
^
    
15.06.2016 / 10:29