There are two ways to do this. The first, which may be easier, is to create a new variable and add *sum* to it every time you print out a number.

A second alternative, which may be more efficient if you aren't already using such a loop, is to look at a bit of mathematics and calculate it. You'd need to look at arithmetic progressions.

By the way, while sum++ adds one to the value of *sum*, you can put any statement in that section. sum += 2 adds two to *sum *each time. Clearly all odd numbers are 2 apart, so your code may be more efficient if you found the highest and lowest odd value, and then counted in twos. It's just a suggestion though, your code works fine at present.