I'm not getting the correct frequencies. When I execute ./notes, C4 through G#4 all return 220, and A4 through B4 return 440.

I've determined that the problem must be with pow(), I just don't know what to do about it. The value of my variable int index calculates as expected.

Note that I'm working from A0 = 27.5 Hz, rather than A4 = 440 Hz. Here's my code:

[edited out code per academic honesty guidelines]

    // Multiply A0 by 2^(n/12), round result, cast as int
    return (int)(round(pow(2, index / 12) * 27.5));

(pow(2, index / 12)

the issue is that both index and 12 are integers, so with integer division, the result will always be a whole number.

Try using 12.0 instead of 12 to force a floating point result.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .