#include <iostream>
usingnamespace std;
int main ()
{
int sump=0, sumn=0, ctr=0;
int num, n;
cout << "This program intends to add all positive and negative given integers";
cout << endl;
cout << endl;
cout << "Please enter input size: ";
cin >> n;
cout << endl;
cout << endl;
for (ctr=0; ctr<n; ctr++)
{
cout << "Enter the Integer value: " << (ctr++) ": ";
cin >> num;
if (num>0) sump = sump+num;
if (num<0) sumn = sumn+num;
}
cout << endl << "The sum of all positive integers: " << sump;
cout << endl << "The sum of all negative integers: " << sumn;
cout << endl;
cout << endl;
system ("pause");
}
with ctr + +, the compiler takes the last value reached by ctr in the for loop and when inserted into the
cout << (ctr + +),
it still increases by 1;
while if you consider (ctr +1),
the compiler takes the initial value of ctr,
ctr = 0;
and the sum 1, then in the for loop, via ctr + +, will increase the value of one at a time.
Can you try this, if You change (ctr + 1), with (ctr+4)