I can not make a vector point correctly to function that it belongs to

0

I have tried several times, but the compiler does not understand the references made in the header of the void CalculaValorparaPagar(float ValorPago[MAX], float Quant_Kwh[MAX],float Preco[MAX], int bandeira[MAX], int tipo[MAX]) function and the main CalculaValorparaPagar(&ValorPago[MAX],Quant_Kwh,Preco,bandeira,tipo/i/); and gives the following error:

  

[Error] can not convert 'float' to 'float' for argument '1' to 'void   CalculateValue to Pay (float, float, float, int, int)

How should I proceed?

                #include <stdio.h>
                //#include "headerfiledoconsumo.h"
                #define MAX 2
                int x;  
                float Imposto[MAX], Taxa_ilum [MAX];
                float Taxa_Band_Tar [MAX];
                float Quant_Kwh [MAX];
                int tipo [MAX];
                float ValorPago[MAX];
                float Preco[MAX];
                int bandeira[MAX];

                //void CalculaValorparaPagar();
                //void fazperguntas();
                //void imprimevalorpagar();

                void fazperguntas(/*float Quant_Kwh[MAX],float Preco[MAX],int tipo[MAX],int bandeira[MAX]*/){

                for (int i= 0; i<MAX; i++){

                //printf("Informe seu nome:\n");
                //scanf("%s", &nome[i]);
                printf("Informe seu consumo em KW: \n");
                scanf("%f", &Quant_Kwh[i]);
                getchar();
                printf("Digite o preco do Khw: \n");
                scanf("%f", &Preco[i]);
                getchar();
                printf("Informe o tipo de consumidor que voce eh: 1(residencial), 2(comercial), 3(Industrial)\n");
                scanf("%d", &tipo[i]);
                getchar();
                printf("Informe a bandeira tarifaria: Verde(1), Amarela(2), Vermelha(3)\n");
                scanf("%d", &bandeira[i]);
                getchar();

                }
                }



                void CalculaValorparaPagar(float *ValorPago[MAX], float Quant_Kwh[MAX],float Preco[MAX], int bandeira[MAX], int tipo[MAX]){


                    //int i = 10;

                    for(int i=0; i<MAX;i++){

                    if (bandeira[i] == 1){
                        Taxa_Band_Tar[i] = 0;
                    }

                    if(bandeira[i] == 2 || Quant_Kwh[i] > 100){

                        x = (Quant_Kwh[i]/100);
                        Taxa_Band_Tar[i] = x*3.5;
                    }

                    if(bandeira[i] == 3 || Quant_Kwh [i] >100){

                        x = (Quant_Kwh[i]/100);
                        Taxa_Band_Tar[i] = x*10.5;
                    }


                    if (tipo[i] == 1){

                        Taxa_ilum[i] = 23.45;
                    }

                    if(tipo[i] == 2){

                        Taxa_ilum[i] = 29.23;
                    }

                    if(tipo[i] == 3){

                        Taxa_ilum[i] = 37.06;
                    }



                    Imposto[i] = 0.04*Quant_Kwh[i] + 0.02*Taxa_ilum[i];
                    *ValorPago[i] = Quant_Kwh[i]*Preco[i] + Taxa_ilum[i] + Imposto[i] + Taxa_Band_Tar[i];

                    }
                }


                    void imprimevalorpagar(){

                        for(int i = 0; i<MAX; i++){ 

                 printf("Consumidor %d  Valor a pagar: %f\n", i,ValorPago[i]); 
                }

                }






                int main() {



                fazperguntas();


                CalculaValorparaPagar(&ValorPago[MAX],Quant_Kwh,Preco,bandeira,tipo/*i*/);


                imprimevalorpagar();

                }
    
asked by anonymous 14.05.2017 / 22:29

1 answer

0

I've already commented how much I hate printf and scanf ? Anyway, ignore.

The message that Clang displays is much more enlightening:

  

list.c: 24: 5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]

scanf("%f", &Quant_Kwh[i]);

^~~~~ ~~~~~~~~~~~~~~~~~~~
     

list.c: 27: 5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]

scanf("%f", &Preco[i]);

^~~~~ ~~~~~~~~~~~~~~~
     

list.c: 30: 5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]

scanf("%d", &tipo[i]);

^~~~~ ~~~~~~~~~~~~~~
     

list.c: 33: 5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]

scanf("%d", &bandeira[i]);

^~~~~ ~~~~~~~~~~~~~~~~~~
     

list.c: 110: 25: warning: incompatible pointer types passing 'float *' to parameter of type 'float **' [-Wincompatible-pointer-types]      

CalculateValue to Pay (& PaidValue [MAX], Quant_Kwh, Price, flag, type / i /);

                    ^~~~~~~~~~~~~~~
     

list.c: 41: 35: note: passing argument to parameter 'valuePago' here

     

void CalculateValueToPay (float * Payload [MAX], float Quant_Kwh [MAX], float Price [MAX], int flag [MAX], int type [MAX]                                     ^

     

5 warnings generated.

The compiler points out that you tried to pass float* as if it were float**

And while running, the little creature gives a beautiful Segmentation Fault. The problem is to treat as a reference something that is already a vector.

But, in particular, I believe you should implode this code and do something different. I'll list what I see as problematic in your code:

  • Global variables. As I imagine you are a beginner, I will be more absolute: do not use global variables. Get away from them like demons flee from Van Helsing.

  • Magic constants. For example, what would this 3.5 be in this line: Taxa_Band_Tar[i] = x*3.5; ? What is the "meaning of life" of this value? What about the other values? Magical constants of this genre must be named and, if possible, placed in a header file .

  • Functions with too many parameters. Why both parameters in the same function? From what I've noticed, these parameters are somehow related, as if they were attributes of some object in the real world - namely, a light bill.

15.05.2017 / 01:40