#include<iostream>
usingnamespace std;
int main()
{
#include<iostream>
usingnamespace std;
int main()
{
int positiveInteger = -1; // its good to initialise your variables
int startingNumber = 1;
do
{
cout << "Please input a positive integer" << endl;
cin >> positiveInteger;
if (positiveInterger >= 0) { // check if value is positive
int result = 0;
for (int i=startingNumber; i <= positiveInteger; i++)
{
result += i;
cout << result;
}
cout << result<<endl;
}
while(positiveInteger<=0);
} else {
cout << "Invalid input, program terminating!" << endl;
return -1;
}
return 0;
}
}
it needs a loop to validate it... meaning if the input is invalid it returns to starting statement, not end the program.and why is positiveinteger = -1 ?