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...
int sum = 0, odd = 1, even = 2, input, num;
cout << "\nEnter a positive integer: ";
cin >> input;
while (num <= input)
cout << sum << endl;
cout << num << endl;
sum = sum + num;
cout << "\nThe sum of the integers from 0 to your number is: " << sum;
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.