צריך להבין את cin
cin's stream operators (operator >>) always try to 'eat' as much as needed - but not more. take the following code for example: int i; char ch; cin >> i >> ch; The result for the input "123g<Enter>" will be i = 123, ch = g. cin's operator >> (int&) 'ate' the digits '123' and stopped when it reached 'g'. At that point i = 123 and the input stream contains 'g\r\n'. The next call is cin's operator >> (char&) which takes the first non-whitespace character from the stream, 'g' in our case, then stops. At this point i = 123, ch = 'g' and the input stream contains '\r\n'. Another call to one of cin's operator >> () will simply skip all non-whitespace characters (and if necessary, wait for user input). That's why the inputs "123 g<enter>", "123<enter><enter><enter>g<enter>" all yield the same result. But the getline() function is a different story. In that function whitespace *matters*. So when the last cin's operator >>() leaves '\r\n' in the input (in your case, operator >>(string&) ), getline immediately sees a newline and returns an empty string. The solution? 'eat' all whitespace before calling getline(). You can do it with std::ws manipulator: change cin >> hand; to cin >> hand >> ws;
חשוב גם לדעת איך מתמודדים עם שגיאות - למשל אם המשתמש מכניס אותיות במקום מספרים. חפש בשאלות הנפוצות, נדמה לי שיש שם קישור שמסביר את הנושא.