Adnanqadri wrote: |
---|
I am trying to compile it in Dev.C++ on win 7 x64 but giving errors. |
Just a small tip for the future: If you have compilation errors - then post them. It just makes life easier for the rest of us. In this case it's a good thing
LowestOne has an eagle eye - things like that can be particularly hard to spot.
A couple of other things to help you out:
sum = sum + number;
Can be written like this:
sum += number;
There are other operators like this - read about them in the reference section link at the top left of this page.
number = number + 1;
If incrementing by 1 and the variable is of int type, then do this:
number++;
There is also the decrement version
number--
and prefix
--number
& postfix versions which make a differences on assignment.
There is also a good tutorial in the Documentation section.
Finally there a lot of good stuff in this book by the inventors of the C language - worth reading the first 4 chapters at least. Might be handy to do some of the exercises as well - do them in C++ rather than C though.
Hope all goes well.