I dont know how to make the question stop popping up

I have to write a program that uses a loop to get the sum of all integers from up to 1 entered. For example is 3 is entered the sum should be 1+2+3 which is 6. So 6 will show. However this code needs to reject numbers under 1. With the code i have it rejects it but the code keeps going on forever and ever.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{
	int num, sum = 0;
	cout << "Enter a positive integer value.";
	cin >> num;

	while (num<0)
	{
		cout << "Please enter a positive integer number.";
		cin >> num;
	}

	for (int i = 1; i >=num; i++)
	{
		sum += 1;
	}
	cout << "sum of all the integers from 1 up to " << num << " is " << sum << endl;
	cin.get();
	return 0;
}
Line 9: This is only rejecting numbers less than 0. You stated you want to reject numbers < 1.

Line 15: Your termination condition is incorrect. This will cause your loop to go forever.

Line 17: Don't you want to add i, not 1?
Topic archived. No new replies allowed.