Print information during execution The best way to find errors is to print a lot of information about the internal state of the program. For instance, if a program remains frozen, the first thing to do is to print something when a few checkpoints are met cout << "Checkpoint #1\n"; for(int i = 1; i < 1000; i++) cout << "i = " << i << "\n"; cout << "Checkpoint #2\n"; for(int j = 0; j < 100; j = j*2) cout << "j = " << j << "\n"; cout << "Checkpoint #3\n"; Also, printing values supposed to vary or to remain constant is a good way to spot errors. Write the same routine twice Usually, any routine can be written in a short, dirty, computationally expensive and maybe even numerically approximative way. This is a good technique to check that the fancy and correct version does what it is supposed to do. For instance, computation of a deri...
Learn C++ Programming fast and easy, find C++ Program Codes