Hello, sorry for this silly question. I'm really new to C++. I really want to know why can't i get the summation from 50 to 100 when i initialize the "sum" variable inside the for loop? Why do i need to put it in the main function and before the for loop?
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
for(int i=50; i <=100; ++i){
sum = sum + i;
cout << "the sum is " << sum << endl;
}
return 0;
}