C++ function Error: cannot be used as a Function

Asked

Viewed 977 times

0

square cannot be used as a Function. Can anyone tell me how to fix?

#include <iostream>
#include <string.h>
#include <sstream>
#include <cmath>
using namespace std;
struct leituras{
  float vetor[1000];
  int n;
}n1;
int quadrados(leituras n1, int i, float desvio_qualquer, float *quadrados);
int main ()
{
    int i;
    float soma, media, desvio, desvio_qualquer, soma_dos_desvios_de_leituras,x,quadrados;
    cout << "Programa para calcular a media das leituras de um experimento e o desvio da media, o programa trabalha com no maximo 1000(mil) leituras.\n";
    cout << "Digite o numero de leituras que seram inseridas no programa, sendo inteiro não negativas e diferente de zero e menores ou igual a 1000,e use pontos e não virgulas para expressar numeros decimais :\n";
    cin >> (n1.n);
    if(n1.n != 0) {
        for( i=0; i<n1.n; i++)  {
            cout << "Digite as leituras:\n ";
            cin >> (n1.vetor[i]);
            }
        for( i=0; i<n1.n; i++)  {
            soma = soma+n1.vetor[i];
}
        media=soma/n1.n;
        for( i=0; i<n1.n; i++)  
        {
            desvio_qualquer = n1.vetor[i] - media;
            quadrados(n1.n, i, desvio_qualquer, &quadrados);
            soma_dos_desvios_de_leituras = soma_dos_desvios_de_leituras + quadrados;
    }
        x=pow(n1.n,-1);
        desvio=sqrt(x*soma_dos_desvios_de_leituras);
        cout << "A media é: " << media << " \n E o desvio é: " << desvio << endl;

}
    else {
        cout << "Digite a leitura:\n ";
        cin >> (n1.vetor[1]);
        cout << "A media é: " << n1.vetor[1] << " E o desvio é 0(zero)" << endl;
}


  return 0;
}

int quadrados(leituras n1, int i, float desvio_qualquer, float *quadrados) {

    for( i=0; i<n1.n; i++){
        *quadrados = desvio_qualquer*desvio_qualquer;
}
return 0;
} 
  • It would be nice to at least indent the code right. As it is it gets hard to even read.

1 answer

1

Your code has the following errors:

  1. Missing a key at the end of the code }

  2. On line 32 you are passing an incorrect parameter

Your code:

quadrados(n1.n, i, desvio_qualquer, &quadrados);

Correct:

quadrados(n1, i, desvio_qualquer, &quadrado);

Note that I changed the name of the third parameter, do this also in the declaration because the compiler is getting confused between its struct and the variable float.

  • Thank you very much!

  • As you are new user you may not know. Next to my answer has a "right / v" sign that you can mark if you consider the answer as a solution to your problem. This serves to encourage those who answer the questions and get recorded that their problem has been solved

Browser other questions tagged

You are not signed in. Login or sign up in order to post.