I have been looking at this til my eyes are crossed. The assignment is to convert an "alpha" phone number into the corresponding digits allowing the user to enter more than once and putting the hyphen in the correct place. If I remove the while statement the phone number comes out but when I add it, it does not work. Can anyone point me in the right direction?
thanks!
You need to add a cin.ignore() statement before your getline(cin, phoneNumber) line. It's reading the previous "y" that you entered and therefore won't allow you enter another string. After doing this your program runs fine. (although I would suggest adding an endl after the user enters a string)
Also, don't forget to add your #include<string> header
Alternatively, change line 19 to getline(cin >> ws, phoneNumber);.
What's happening right now is that your cin >> play; is leaving a newline in the input buffer which gets eaten by getline instead of your input.
Adding cin >> ws will make cin gobble up the whitespace first so that the getline will work as expected.