# Pset3 Helpers.c Frequency Not Working

Right now I am working on Pset3 with Music. I'm focusing on getting the frequency (in Hz) of all the octaves of A. I am including accidentals in my work as well. The problem is that A4 returns 449 instead of the expected 440. I've tried to use Google and I even checked my work but I couldn't find any logical issues.

``````int frequency(string note)
{
const char* n = note;
if (strncmp(&n,"A", 1) == 0 && strncmp(&n,"4", 1) == 0) {
return 440;
}
else if (strncmp(&n,"A", 1) == 0){
if (strncmp(&n,"#", 1) == 0){
if (atoi(&n) > 4) {
int freq = round(440*2^(atoi(&n)-4));
return round(freq * 2^(1/12));
}
else {
int freq = round(440/2^(4-atoi(&n)));
return round(freq * 2^(1/12));
}
}
else {
if (n > 4) {
return round(440*2^(atoi(&n)-4));
}
else {
return round(440/2^(4-atoi(&n)));
}
}
}
}
``````

Any and all help would be appreciated :)

Note that C's `^` operator is bitwise XOR, not power. Also, in C, `1/12` equals `0` (integer division truncates, you could avoid this by using floating point values like `1.`, yes this decimal point makes it a floating point number). You might want to include `math.h`.
And if you want to compare single characters, I find `strncmp` a bit overkill, `if (n == 'A')` should work as well. Since octaves are single-digit, you could even use `n-'0'` instead of `atoi(&n)`. And in `n > 4` you're comparing a character to a number. As characters are 8-bit integers, the compiler thinks this is fine. And you seem to access the wrong element `n` on the last few lines, where the number is in `n`.
• You probably did `n == "A"`, not `n == 'A'`, the kind of quotation marks matter in C (unlike for example Python or JavaScript). I still don't get how you might receive 449 as an answer with above code. But have you understood all the other mistakes I mentioned? – Blauelf Jan 13 '18 at 20:23