when i run this code.
output going bit crazy
output:
enter name: aa
eneter account :111
enetner name enter account
not letting me entrance a name and already that account jump
how should i avoid this?
That's a very common problem when mixing getline() and formatted input using the >> operator.
There's an imbalance because the getline() will read until the end of the line, and discard the newline character '\n'. On the other hand, cin >> account; stops reading as soon as it encounters any trailing whitespace and leaves the newline character '\n' remaining in the input buffer. On the second iteration, the getline finds that unwanted newline and read an empty string.
Possible solutions:
1. use the ws manipulator to skip any trailing whitespace after the account number:
2. Use ignore() to read and ignore any characters whether whitespace or not, after the account number. In the following example, it will ignore up to 1000 unwanted characters, or until the delimiter '\n' is found.