Im working through a book i bought learn C++ how to program 2003, and it seems most of the examples compile with zero erros or warnings, yet they dont flow correct. Iv even tried compiling the include .cpp files on the cd and they still have the same error. Can anyone spot the problem, would be nice to figure out what hes doing wrong in this loop because he uses the same loop setup in the next 2 chapters. I have a feeling its to do with char response[256], it doesnt seem to let it recieve any input , and then jumping into the if (strlen(response) etc return 1;, any help please. I also note that it would be better to use functions or atleast a switch statement, but im working through a book.
If you add: cin.ignore(); between lines 18-19, and again at 64-65, it will solve the problem.
cin >> moreBanking; is leaving a \n character in the stream and when getline is called, it is finding the \n and responding as if you hit enter without typing anything else.
When you use cin it ignores white space (\n, ' ', TAB) until it gets to some data in the input buffer. It then extracts that data until it reaches another white space character. That last white space character is left in the buffer. The next time you use cin, the process it repeated (that white space that was left behind is at first ignored.) But when you use getline, it works differently. It collects all data until it reaches the delimiter character (which defaults to '\n') which it also extracts, but does not include in the variable it is working on.
So in this case, cin left the '\n' behind and it cut your getline short.