Variable-sized object may not be initialized

0

Problems in C. This error is appearing:

  

Variable-sized object may not be initialized

What can I do to fix this error? Being that I have already initialized everything.

LINE 66, 67 and 68

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

void painelPerguntas();
double calculoQtIteracao(double raizA, double raizB, double testeParada);
double calculoC(double raizA, double raizB);
double calculoModuloAB(double raizA, double raizB);
double calculoFxF(double raizA, double resultC);
char verificacaoSinal(double resultFxF);
double trocaAB(double raizA, double raizB, double resultC, char verificacaoSinal);

int main(){
    painelPerguntas();
}

void painelPerguntas(){
    double raizA = 0, raizB = 0, testeParada = 0;
    printf("RAIZ [a]: ");
    scanf("%lf", &raizA);
    fflush(stdin);
    printf("RAIZ [B]: ");
    scanf("%lf", &raizB);
    fflush(stdin);
    printf("PARADA: ");
    scanf("%lf", &testeParada);

    //CALCULO QUANTIDADE DE ITERAÇÕES
    calculoQtIteracao(raizA, raizB, testeParada);
    double qtIteracoes = calculoQtIteracao(raizA, raizB, testeParada);
    int qtIteracao = qtIteracoes;


    // CALCULA VALOR DE C
    calculoC(raizA, raizB);
    double resultC = calculoC(raizA, raizB);;

    //CALCULA |A-B|
    calculoModuloAB(raizA, raizB);
    double resultAB = calculoModuloAB(raizA, raizB);

    //CALCULA F(A).F(C)
    calculoFxF(raizA, resultC);
    double resultFxF = calculoFxF(raizA, resultC);

    //RESULTADO DE SINAL
    verificacaoSinal(resultFxF);
    char resultSinal = verificacaoSinal(resultFxF);

    /*
    printf("\n    N        |    A        |    B         |    C         |   |A-B|        |    F(A).F(C)       |  SINAL");
    printf("\n    %d        |   %lf  |   %lf   |   %lf   |    %lf    |      %lf      |   %c  ", qtIteracao, raizA, raizB, resultC, resultAB, resultFxF, resultSinal);
    */

    //TROCA A/B COM C
    trocaAB(raizA, raizB, resultC, resultSinal);
    double resultTrocaAB = trocaAB(raizA, raizB, resultC, resultSinal);

    //EXIBIÇÃO DO RESULTADO
    printf("\n    N        |    A        |    B         |    C         |   |A-B|        |    F(A).F(C)       |  SINAL");
    int cont = 0;
    for(cont = 0; cont <= qtIteracao; cont++){
        double vetorA[cont] = resultTrocaAB, vetorB[cont] = resultTrocaAB, vetorC[cont] = resultC, vetorAB[cont] = resultAB;
        double vetorFxF[cont] = resultFxF;
        char vetorSinal[cont] = resultSinal;

            printf("\n%d", cont);
    }
}

double calculoQtIteracao(double raizA, double raizB, double testeParada){
    double calculo = (log10(raizB - raizA) - log10(testeParada)) / log10(2);
    return round(calculo);
}

double calculoC(double raizA, double raizB){
    double calculo = (raizA + raizB) / 2;
    return calculo;
}

double calculoModuloAB(double raizA, double raizB){
    double calculo = raizA - raizB;
    if(calculo < 0){
        calculo = calculo * -1;
        return calculo;
    }else {
        return calculo;
    }
}

double calculoFxF(double raizA, double resultC){
    double calculoFA = (pow(raizA,3)) - 3*raizA - 1;
    double calculoFC = (pow(resultC,3)) - 3*resultC - 1;
    double calculoFAxFC = calculoFA * calculoFC;
    return calculoFAxFC;
}

char verificacaoSinal(double resultFxF){
    if(resultFxF < 0){
            char sinalNegativo = '-';
            return sinalNegativo;
    }else{
        char sinalPositivo = '+';
        return sinalPositivo;
    }
}

double trocaAB(double raizA, double raizB, double resultC, char verificacaoSinal){
    if(verificacaoSinal == '+'){
            raizA = resultC;
            return raizA;
    }else{
        return raizA;
    }

    if(verificacaoSinal == '-'){
            raizB = resultC;
            return raizB;
    }else{
        return raizB;
    }
}
    
asked by anonymous 06.11.2016 / 17:13

1 answer

3

I have compiled declaring the undeclared variables, which was the problem (for me that is a mistake.) Maybe the question is not clear yet.I gave a good general improvement, but the code still has several problems that I can not solve without knowing I've used the vectors to avoid the warning of the ideone compiler that always stays connected, as it should be.

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

double calculoQtIteracao(double raizA, double raizB, double testeParada) {
    return round((log10(raizB - raizA) - log10(testeParada)) / log10(2));
}

double calculoC(double raizA, double raizB) {
     return (raizA + raizB) / 2;
}

double calculoModuloAB(double raizA, double raizB) {
    return abs(raizA - raizB);
}

double calculoFxF(double raizA, double resultC){
    return (pow(raizA, 3) - 3 * raizA - 1) * (pow(resultC, 3) - 3 * resultC - 1);
}

char verificacaoSinal(double resultFxF){
    return resultFxF < 0 ? '-' : '+';
}

double trocaAB(double raizA, double raizB, double resultC, char verificacaoSinal) {
    return verificacaoSinal == '+' ? resultC : raizA;
    //o código aqui estava todo errado, isso ainda está errado, mas é o que executaria
}

void painelPerguntas() {
    double raizA = 0, raizB = 0, testeParada = 0;
    printf("RAIZ [a]: ");
    scanf("%lf", &raizA);
    fflush(stdin);
    printf("RAIZ [B]: ");
    scanf("%lf", &raizB);
    fflush(stdin);
    printf("PARADA: ");
    scanf("%lf", &testeParada);

    double qtIteracoes = calculoQtIteracao(raizA, raizB, testeParada);
    double resultC = calculoC(raizA, raizB);
    double resultAB = calculoModuloAB(raizA, raizB);
    double resultFxF = calculoFxF(raizA, resultC);
    char resultSinal = verificacaoSinal(resultFxF);
    double resultTrocaAB = trocaAB(raizA, raizB, resultC, resultSinal);

    printf("\n    N        |    A        |    B         |    C         |   |A-B|        |    F(A).F(C)       |  SINAL");
    //o problema estava aqui, falta declarar os vetores
    double vetorA[(int)qtIteracoes + 1];
    double vetorB[(int)qtIteracoes + 1];
    double vetorC[(int)qtIteracoes + 1];
    double vetorAB[(int)qtIteracoes + 1];
    double vetorFxF[(int)qtIteracoes + 1];
    char vetorSinal[(int)qtIteracoes + 1];
    //isso também não faz sentido no momento
    for (int cont = 0; cont <= qtIteracoes; cont++) {
        vetorA[cont] = resultTrocaAB;
        vetorB[cont] = resultTrocaAB;
        vetorC[cont] = resultC;
        vetorAB[cont] = resultAB;
        vetorFxF[cont] = resultFxF;
        vetorSinal[cont] = resultSinal;
        printf("\n%d %f %f %f %f %f %c", cont, vetorA[cont], vetorB[cont], vetorC[cont], vetorAB[cont], vetorFxF[cont], vetorSinal[cont]);
    }
}

int main(){
    painelPerguntas();
}

See more or less running on ideone .

    
06.11.2016 / 17:51