Error: cannot Convert float* to float

Asked

Viewed 1,164 times

-1

Error is on the line:

quadrados = (desvio_qualquer * desvio_qualquer); 

Error: Cannot Convert Float* to Float

#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 + pow(desvio_qualquer,2);
    }
        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;
//}                                 Não entendi o erro.

1 answer

4

Remember that when you want to change the value of a pointer you should use *

So the line goes like this:

*quadrados = (desvio_qualquer * desvio_qualquer);

In your case you were trying to give a value to the pointer, which represents a memory address.

  • Thanks, but it’s still not working, look please:

  • @user3720765, I have tested and the error no longer occurs. What problem is occurring? Take a look at the code that is here: http://textuploader.com/0bqr and try to create a new project by pasting this code into the main

  • struct readings{ float vector[1000]; int n; }n1; int squares(readings n1, int i, float deviation_any, float *squares); int main() { int i; float sum, media, deviation, deviation_any, soma_dos_deviation_de_readings,x,squares; media=sum/n1.n; for( i=0; i<n1.n; i++) { deviation_any = n1.vector[i] - media; squares(n1.n, i, deviation_any, squares); soma_dos_deviation_de_readings = soma_dos_deviations_readings + squares; Return 0; } int squares(n1, int i, deviation_float any, float *squares){ for( i=0; i<n1.n; i++){ *squares = (deviation_any * deviation_any);

  • now says you can’t use the square function

  • 1

    In this case if your problem "cannot Convert float* to float" has been solved please mark the answer as valid and open a new question so that more people can help you. Remember to add the formatted source code.

Browser other questions tagged

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