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[0],"A", 1) == 0 && strncmp(&n[1],"4", 1) == 0) {
printf("Your 'if' statement works");
return 440;
}
else if (strncmp(&n[0],"A", 1) == 0){
if (strncmp(&n[1],"#", 1) == 0){
if (atoi(&n[2]) > 4) {
int freq = round(440*2^(atoi(&n[2])-4));
return round(freq * 2^(1/12));
}
else {
int freq = round(440/2^(4-atoi(&n[2])));
return round(freq * 2^(1/12));
}
}
else {
if (n[1] > 4) {
return round(440*2^(atoi(&n[1])-4));
}
else {
return round(440/2^(4-atoi(&n[1])));
}
}
}
}
Any and all help would be appreciated :)