Skip to main content
1 of 5

control reaches end of non-void function

I have problem with my code (I guess). I have got the control reaches end of non-void function error even though my ifs (i think so ;) ) are covering all of the possibilities.

Please have a look:

int frequency(string note)
{

    int n = 0; // fraction(?) counter (n/12)
    int hz = 0; //Hz of A in the Octave
    int noteHz = 0;
    bool specialCase = false;
    float temp = 0;



    //2nd step: calculate the A hrtz of octave
    if (note[strlen(note) - 1] < 4)
    {
        for (int i = 1; 4 - i != strlen(note); i++)
            hz /= 2;
    }

    else if(note[strlen(note) - 1] > 4)
    {
        for (int j = 1; 4 + j != strlen(note); j++)
            hz *= 2;
    }

    else
        hz = 440;

    //!!!!THIS NEEEDS TO COME FOR AN END TO BE BETTER IMPLEMENTED - RIGHT NOW ITS BUGGY!!!!
    //1st step: check if we do have special representation of notes or "normal"


    if (note[1] == '#' && note[0] == 'B')//- this was my 1st code in this place this below (code with use of strncmp):
    {
        hz *=2;
        specialCase = true;
    }
    else if (note[1] == 'b' && note[0] == 'A')
    n++;
    else if (note[1] == '#')
    n++;
    else if (note[1] == 'b')
    n--;
    else
    n = n + 0;


    if (specialCase)
    {
        n += 9;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }

    else if (note[0] == 'A')
    noteHz = hz;

    else if(note[0] == 'B' && specialCase == false)
    {
        n += 2;
        temp = pow(2, n/12);
        noteHz = hz * round(temp);
    }

    else if (note[0] == 'C')
    {
        n += 9;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }

    else if(note[0] == 'D')
    {
        n += 7;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }

    else if(note[0] == 'E')
    {
        n += 5;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }

    else if(note[0] == 'F')
    {
        n += 4;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }
    else if(note[0] == 'G')
    {
        n += 2;
        temp = pow(2, n/12);
        noteHz = hz / round(temp);
    }
    else
        n += 0;

}

I hope code is clear I have some comments on it. What is wrong here?