That is because you are using two methods to read the input:
the operator>> (istream) - C++ Reference
] (also called extraction
operator) and istream::getline - C++ Reference
The first will read strings until a white space character occurs (which includes the
new line when pressing Enter) without storing and reading that white space character while
reads upto and including the new line character storing it not in the supplied buffer.
So the first will read the input (assuming "YES") but the new line character which stops the reading is still in the input buffer. When calling
afterwards that will initially read the new line character and return an empty buffer.
The common solution to this problem is to avoid mixing these two input methods. In most cases using
is the better method because it allows to enter strings containing spaces.