When I ran my code through the compiler for notes.c, I got the following error: helpers.c:88:26: runtime error: value inf is outside the range of representable values of type 'int'. It then returned these values in the terminal: C4: -2147483648 C#4: -2147483648 D4: -2147483648 D#4: -2147483648 E4: -2147483648 F4: -2147483648 F#4: -2147483648 G4: -2147483648 G#4: -2147483648 A4: -2147483648 A#4: -2147483648 .This is my code from the int frequency(string note, const string NOTES[]) function in helpers.c:
int frequency(string note, const string NOTES[]){
int digit;
char alphabetsTwo[] = {0,0,0};
char alphabetsOne[] = {0,0};
int positionOfAlpha;
//Determine length of note and split into alphabet and digit
if(strlen(note) == 2){
alphabetsOne[0] = note[0];
digit = note[1];
}
else if(strlen(note) == 3){
alphabetsTwo[0] = note[0];
alphabetsTwo[1] = note[1];
digit = note[2];
}
//Convert flat to sharp
if(note[1] == 'b'){
//Ensure that "b" changed to "#"
alphabetsTwo[1] = '#';
//Changing letter (e.g. from 'E' to 'D')
if((int)(note[0]) <= 71 && (int)(note[0]) > 65){
alphabetsTwo[0] = (char)((int)(note[0] - 1));
//Only for changing from 'G' to 'A'
}else if((int)(note[0]) == 65){
alphabetsTwo[0] = (char)(71);
}else{
fprintf(stderr, "Alphabet doesn't exist!\n");
return 1;
}
}
//Iterate through NOTES[] to find position of alphabet
for(int i=0, n = 12; i<n; i++){
if(NOTES[i] == alphabetsTwo || NOTES[i] == alphabetsOne){
positionOfAlpha = i;
}
}
//Find difference between position of alphabet and A in NOTES[]
int diffAlpha = positionOfAlpha - 9;
//Store in temp variable
float power = diffAlpha/12;
float temp = 440*powf(2.0, power);
//Find difference in octaves
int diffNum = digit - 4;
float floatFrequency = round(temp*powf(2.0, diffNum));
int finalFrequency = (int)(floatFrequency);
return finalFrequency;
}
Where is it that I've went wrong? Thank you.