Emacs always compiles the version of the program that is saved on disk. If you make changes to the program in the Emacs buffer but don't save those changes before you compile, then the version of the program that you see in the Emacs window will be different than the version that will be compiled! How confusing!
For this reason it is always a good idea to make sure that you've saved all your changes before Emacs compiles your program. Fortunately, Emacs helps you with this-if it sees that you've made some changes but haven't yet saved them, it ask you if you want to do so.