Hello, I am working out of the Accelerated C++ book. I have been learning C++ for a couple years now (teaching myself as I have time). I have run into a small issue in chapter 3 of this book and am not sure what to do about it. I have tried to run the example programs from the chapter and they will not run. I believe the problem is at the section:
while(cin >> x)
{
++count;
sum += x;
}
I have commented out code from here on, and the program runs fine. When I add this code in, the program allows me to enter the data, but then immediately exits without finishing. The output window in VSC++ 2010 says the exited with code 0.
I was wondering what would be causing the program to exit without finishing? Anyone have any ideas or suggestions of how to get this to run completely?
Here is the full code I was using. (I deleted the code because I thought I might be infringing on the copyright). I added the last bit before return 0 to keep the console window open until I saw the finished program.
Edit to issue: I have continued to work with the program. I have not figured out what I am doing wrong, but I can redefine what is happening. It seems the program is continuing to run, but I can no longer use cin. I have tried placing cin.clear() after my while loop as amrazek mentioned, and it has not corrected the problem. I will continue to look into the issue.