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.
#include <iostream>
usingnamespace 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;
}