# pset3 music - value inf is outside the range of representable values of type 'int'

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 = note;
digit = note;
}
else if(strlen(note) == 3){
alphabetsTwo = note;
alphabetsTwo = note;
digit = note;
}
//Convert flat to sharp
if(note == 'b'){
//Ensure that "b" changed to "#"
alphabetsTwo = '#';
//Changing letter (e.g. from 'E' to 'D')
if((int)(note) <= 71 && (int)(note) > 65){
alphabetsTwo = (char)((int)(note - 1));
//Only for changing from 'G' to 'A'
}else if((int)(note) == 65){
alphabetsTwo = (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.

In `digit = note;`, you assign a digit character, but you meant the value associated with the digit. Similar to `caesar`, you can subtract `'0'` to convert digits `'0'` to `'9'` to numbers `0` to `9`.
String comparison is done with `strcmp` or one of its siblings, not `==`. `==` would test whether those are the same string (same memory location of characters), not strings of same content.
I'd say string comparison here is overkill, and you could succeed with processing single characters. Also, `diffAlpha/12` is an integer divison, creating an integer again. Using `/12.0` would make it a floating point division.
• Does `./synthesize boat.wav < songs/boat.txt` throw any error? Does `valgrind ./synthesize boat.wav < songs/boat.txt` point you to any mistake? Jul 16 '18 at 8:10