12-15-2009, 02:12 PM
Hey
Why doesn't this work:
For 'x', I should be getting the same as 'i' (1 going down to 100) but I get 5050.
Does anyone know what the problem is?
P.S - I'm learning from a book, so any mistakes are Jeff Cogswell's fault.
Why doesn't this work:
PHP Code:
#include <iostream.h>
int main() {
int x = 0;
int i;
for (i = 1; i <= 100; i++) {
x += i;
}
cout << x << endl;
return 0;
}
For 'x', I should be getting the same as 'i' (1 going down to 100) but I get 5050.
Does anyone know what the problem is?
P.S - I'm learning from a book, so any mistakes are Jeff Cogswell's fault.