Sample code with errors for practising debugging skills?

Hello everyone,

I teach C++ programming, and I noticed that many of my students have really bad debugging skills. Even though I've already taught them how to use breakpoints, they still only use them until I tell them "put a breakpoint there and you'll see what's wrong."

I remember when I was in college, one day, a teacher gave us an assignment: it was an already written piece of code. It had a couple of compiler errors, but even after those were fixed, you'd see that the output was different from the sample correct output.

The reason was that some variables were doing things they shouldn't, or for example, there was a tricky line:

1
2
for(i = 0; i < 10; i++);
    cout << i;


Where you could see that there's a semicolon after the for loop, yet with a quick glance one may have skipped noticing it.

So, I was wondering if any of you knew or had any sample code that needs to be fixed so that it can compile, or even better, code that needs to be debugged so that it works properly.

My students are beginner level, but any samples you have could really help me out.

Thanks!
Topic archived. No new replies allowed.