odd number problem

Im just gonna get straight to the point...

Im supposed to make a program that takes the odd numbers from 1000 -> 2000 and then show me the sum of them all together

so 1001,1003,1005.......1995,1997,1999 and then all of those number are supposed to "added" together.

I dont know if this is any help but the code that shows all the numbers between 1000 - 2000 (as far as I know) looks like this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
    int a;
    for (a=1001;a<2000;a=a+2)
    {
            
            cout <<a<<",  ";
            }
            system("PAUSE");
            return EXIT_SUCCESS;
            }



This is a beginners request and im aware of that this is maybe easy for some of you all :D but I would be please if you showed me how the code is supposed to look like and what im missing and what to be added

Also - The program is only supposed to show me the sum of all the odd numbers nothing else.

Thanks for help! :)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
    unsigned int sum = 0;
    for (unsigned int i = 1001; i < 2000; i += 2 ){
        sum += i;
    }
    cout << "The sum is: " << sum << endl;
    cin.ignore();
    return 0;
}
Topic archived. No new replies allowed.