I am new to C++, and I have been reading "C++ Primer, 4th Edition" to help me learn. I do the examples in the book to help me practice. This part of the chapter is covering control structures, but I can't get one of the examples to work for me.
The code is suppose to take any values you input (regardless of quantity) and generate their collective sum. I wrote it correctly, it complied just fine.
I input integers but it doesn't give me the sum, and the program will not stop normally unless I ex out the window or I input something that is a non integer.
int sum = 0, value;
// read till end-of-file, calculating a running total of all values read
while (std::cin >> value)
sum += value; // equivalent to sum = sum + value
std::cout << "Sum is: " << sum << std::endl;
Someone did post on programmersheaven.com forum about this same exact code a few years back, however it didn't help me much or maybe it isn't relevant anymore (some nonsense about ctrl+z, idk).
It would be great if I can get a response soon. I am using Microsoft Visual C++ 2010 IDE.