Compiler reports typing error when there is no typing error

1

I have struct

struct no
{
int numero[2]; 
std::string nome;
float valorDoNome;
struct no *esq, *dir;
};
struct no *raiz, *aux1, *aux2,*favoritos;

The function

    {
    raiz->valorDoNome=0;
    int posicao=1;
    for(unsigned i=0; i<raiz->nome.length(); ++i)
    {

    if(raiz->nome.at(i)=='A' || (raiz->nome.at(i)='a'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(1/posicao);
    }
    if(raiz->nome.at(i)=='B' || (raiz->nome.at(i)='b'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(2/posicao);
    }
    if(raiz->nome.at(i)=='C' || (raiz->nome.at(i)='c'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(3/posicao);
    }
    if(raiz->nome.at(i)=='D' || (raiz->nome.at(i)='d'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(4/posicao);
    }
    if(raiz->nome.at(i)=='E' || (raiz->nome.at(i)='e'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(5/posicao);
    }
    if(raiz->nome.at(i)=='F' || (raiz->nome.at(i)='f'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(6/posicao);
    }
    if(raiz->nome.at(i)=='G' || (raiz->nome.at(i)='g'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(7/posicao);
    }
    if(raiz->nome.at(i)=='H' || (raiz->nome.at(i)='h'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(8/posicao);
    }
    if(raiz->nome.at(i)=='I' || (raiz->nome.at(i)='i'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(9/posicao);
    }
    if(raiz->nome.at(i)=='J' || (raiz->nome.at(i)='j'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(10/posicao);
    }
    if(raiz->nome.at(i)=='K' || (raiz->nome.at(i)='k'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(11/posicao);
    }
        if(raiz->nome.at(i)=='L' || (raiz->nome.at(i)='l'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(12/posicao);
    }
    if(raiz->nome.at(i)=='M' || (raiz->nome.at(i)='m'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(13/posicao);
    }
        if(raiz->nome.at(i)=='N' || (raiz->nome.at(i)='n'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(14/posicao);
    }
    if(raiz->nome.at(i)=='O' || (raiz->nome.at(i)='o'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(15/posicao);
    }
    if(raiz->nome.at(i)=='P' || (raiz->nome.at(i)='p'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(16/posicao);
    }
    if(raiz->nome.at(i)=='Q' || (raiz->nome.at(i)='q'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(17/posicao);
    }
    if(raiz->nome.at(i)=='R' || (raiz->nome.at(i)='r'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(18/posicao);
    }
    if(raiz->nome.at(i)=='S' || (raiz->nome.at(i)='s'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(19/posicao);
    }
    if(raiz->nome.at(i)=='T' || (raiz->nome.at(i)='t'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(20/posicao);
    }
    if(raiz->nome.at(i)=='U' || (raiz->nome.at(i)='u'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(21/posicao);
    }
    if(raiz->nome.at(i)=='V' || (raiz->nome.at(i)='v'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(22/posicao);
    }
    if(raiz->nome.at(i)=='W' || (raiz->nome.at(i)='w'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(23/posicao);
    }
    if(raiz->nome.at(i)=='X' || (raiz->nome.at(i)='x'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(24/posicao);
    }
        if(raiz->nome.at(i)=='Y' || (raiz->nome.at(i)='y'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(25/posicao);
    }
    if(raiz->nome.at(i)=='Z' || (raiz->nome.at(i)='z'))
    {
     raiz->valorDoNome=raiz->valorDoNome+(26/posicao);
    }
    posicao=posicao*100;
}
}

And I call the function

calculaValorDoNome(raiz);

But when I call it gives the error:

[Error] could not convert 'raiz' from 'no*' to 'std::string {aka std::basic_string<char>}'

Even the function asking for a no* and I supplying a no* .

Any idea why?

    
asked by anonymous 23.06.2016 / 23:40

1 answer

3

First, look at this:

if(raiz->nome.at(i)=='A' || (raiz->nome.at(i)='a'))

In particular this:

raiz->nome.at(i)='a'

Note that you used = instead of == . That should not be what you want.

And then we have this function:

calculaValorDoNome(raiz);

However, you did not put the statement for this function in your question. Only her body. It is possible that you have declared it wrong. But that's fine, here is the correct way to declare it:

void calculaValorDoNome(struct no *raiz);

Codes full of Ctrl + C Ctrl + V are horrible. Let's try to simplify it and eliminate this bunch of Ctrl + C Ctrl + V. Also, indenting it properly helps other people understand you (and by indenting the code appropriately in your questions, you'll tend to get more and better answers faster). So your code can be simplified to become this:

struct no {
    int numero[2]; 
    std::string nome;
    float valorDoNome;
    struct no *esq, *dir;
};
struct no *raiz, *aux1, *aux2, *favoritos;

void calculaValorDoNome(struct no *raiz) {
    raiz->valorDoNome = 0;
    int posicao = 1;
    for (unsigned i = 0; i < raiz->nome.length(); ++i) {
        for (int c = 0; c < 26; c++) {
            if (raiz->nome.at(i) == ('A' + c) || raiz->nome.at(i) == ('a' + c)) {
                raiz->valorDoNome += ((c + 1) / posicao);
            }
        }
        posicao *= 100;
    }
}

However, I think this is not yet the algorithm you want, since as soon as posicao reaches the value of 100, whatever the value of c , the expression ((c + 1) / posicao) will result in zero . Note that your original algorithm also had this same problem, since in the original algorithm (x/posicao) will result in 0 for any value of x between 1 and 26 when posicao has a value of 100 or greater. So, as a result, we have only the value of the first character end up making some difference in the calculated value for the name, and I doubt that's what it was meant to be.

Unfortunately, since I do not know what your idea is for an algorithm that gives a name value, I can not fix it without you telling me what it is that you really wanted it to do.

    
24.06.2016 / 00:02