Help with a while loop

Hi! I am trying to write a program that gets an integer from a user and uses a while loop to sum all of the integers from 1 to the number that the user input. Below is my code and its just not working. I'm not sure why...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main()
{
    int sum = 0, odd = 1, even = 2, input, num;

    cout << "\nEnter a positive integer: ";
    cin >> input;
    cin.ignore();

    while (num <= input)
    {
        cout << sum << endl;
        cout << num << endl;
        sum = sum + num;
        num++;
    }

    cout << "\nThe sum of the integers from 0 to your number is: " << sum;

    cin.get();
    return 0;
}


The output for this program is 0... it should be 15 if they entered 5 and so on. Can anyone explain my problem and help me fix it? I think I'm missing something in the logic flow.
'num' must be initialized to 0;
yeah, set num to 0 and you'll get the output you want. I set num=0; and when I input 5 I got 15
Well, that was an easy fix! Its working now... Thank you!
Topic archived. No new replies allowed.