Add
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
after
cin >> c;
Consider the following input:
dog
cat
y
owl
fish
n
If we look at the characters that are present individually in the input stream, we will see:
d o g \n c a t \n y \n o w l \n f i s h \n n \n
The first call getlineconsumes dog\n; the second consumes cat\n, leaving this:
y \n o w l \n f i s h \n n \n
cin >> c y , , :
\n o w l \n f i s h \n n \n
: getline? , . getline owl... .
, , , ( ) .