Error in code from public domain (expected '}' before numeric constant)

I’ve been creating a simple program using the tone() function and succeeded during its first part, with help from the example tone() sketch. I copied and pasted the note values into my own code, and it ran well for a while until it decided that there was something wrong. I checked the program, and to my surprise it was an error in the code I took straight from the example. I don’t see any typos or anything of the sort, and am very sure that it was the exact same code that previously ran successfully. Did I miss anything?

Romance_Troika.ino (1.21 KB)

pitches.h (1.96 KB)

The compiler is your friend and it is never wrong. Two certainties; there is a mistake and you are overlooking it.

You’re missing some commas in your arrays. After fixing that the code will compile. However there is still a serious problem. Do this:
File > Preferences > Compiler warnings > All > OK
Sketch > Verify/compile
Wait for the compilation to finish
Resize the black console window at the bottom of the Arduino IDE window to make it larger and read the warning text in red which is shown:

C:\arduino\arduino-1.8.5\hardware\arduino\avr\cores\arduino\main.cpp: In function 'main':

C:\Users\accou\AppData\Local\Temp\arduino_modified_sketch_418052\Romance_Troika.ino:26:50: warning: iteration 64 invokes undefined behavior [-Waggressive-loop-optimizations]

   int noteDuration = 3000/ noteDurations[thisNote];


C:\Users\accou\AppData\Local\Temp\arduino_modified_sketch_418052\Romance_Troika.ino:25:1: note: containing loop

 for(int thisNote = 0; thisNote < 70; thisNote++){


The noteDurations array contains 64 items so reading it to index 69 is not going to be a good thing. There’s a cool trick that allows you to programmatically determine the length of an array:

sizeof(noteDurations) / sizeof(noteDurations[0]

That divides the size of the array by the size of an array element, which will give you the number of elements in the array. This allows you to write code that automatically adjusts to any song you program:

for(int thisNote = 0; thisNote < sizeof(noteDurations) / sizeof(noteDurations[0]); thisNote++){

Much easier than manually counting the elements in the array and updating the code accordingly.

As TKall said, the compiler is your friend. Always leave warnings turned on so it can help you even more with useful warnings and always pay attention to what it’s saying.