I was just transforming a while loop into a for loop.to learn my for loops
working while loops
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main()
{
int sum = 0, value = 0;
while (cin >> value)
{
sum += value;
cout << "Sum is: " << sum << endl;
}
system("PAUSE");
return 0;
}
for loop (not working)
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
usingnamespace std;
int main()
{
for (int sum = 0, val = 0; cin >> val; sum += val)
cout << "Sum is: " << sum << endl;
system("PAUSE");
return 0;
}