0
any written material on finding errors
i am facing difficulty in finding error pls jelp
1 Answer
+ 4
The easiest way to find errors for a beginner is to limit how many you make. Instead of coding 20 lines of possible errors, code 1 or 2 lines. Prove they work before coding more.
IDE's make it easier as you can watch what happens after each statement is executed. But, outputting debugging information works just as well.
int arr[] = {3, 5, 7};
int sum = 0;
cout << "Entering for loop; sum=" << sum << endl;
for (int i = 0; i < 4; i++) { // bug i will go beyond arr bounds
cout << i << ": sum=" << sum << "+" << flush;
sum += arr[i];
cout << arr[i] << "=" << sum << endl;
}
cout << "exit for loop" << endl;
This will make it obvious that arr[3] is used incorrectly.
https://code.sololearn.com/c9c55D99SacT