Is there a program or something else that can display which code is being executed while I'm running my program? I have a problem with my program where it doesn't "act" the right way and this is why I want to know which part of the code which is being executed when this happens this way I can figure out what's wrong.
What you're asking about is commonly known as a "debugger". You may already have one and you simply need to learn how to use it. Are you using an IDE? What compiler are you using? What operating system?