I'm trying to finish a program that prompts user to input a string, then a menu is displayed giving them options to swap characters or count a character, and then display the newly revised string back to them. At the end of all this it should prompt user if they wish to continue (go back to beginning) or end program. I tried using a do/while loop for the continue option but when it runs a 2nd time the prompt for user to enter a new string doesn't stop to allow the user to enter anything, it just inserts an empty array string instead.
The problem is in the main() function. Also having problems getting it to loop back on invalid entries, I think the problem could be in the default case of the switch loop but i'm not too sure.
Here is my code: it should compile and run so you can see what i'm talking about. thanks for any help i can get this has really had me stumped and it was due thursday.
can anyone help me out as to why the cin.getline statement seems to get skipped everytime the program loops back around?? It allows user to input a string the first time, but then anytime after it skips the user input and sets it as an empty string? please help very confused by this. thanks in advance
1 2 3 4 5 6 7 8 9 10 11 12
do
{
cout << "\n\nWelcome To Ms. String's String Editor!""\n==============================""\nPlease Enter A String:\n"; //get string from user
cin.getline(sentence, 80);
cout << "\nYou Entered: " <<sentence <<"\n"; //show user entry
menu_choice = Func_menu(); //calls menu function
when you go thought to the getline(sentence, 80)
the user inputs a string and when the loop goes around again the same string should be in there so you have to either make a for loop and declare a different string every time or erase the string from the input
*this might be wrong
i tried it out and made it so the getline(sentence, 80)
was changed to cin >> sentence;
and it worked fine
ecker676 - - your's didn't work because it reads getline(cin, sentence, 80) as a function instead of an inputs command.
gregv21 -- did you put my code into your compiler?? The problem isn't that it is keeping the same string saved in the array that the user entered the first time around, its that when it loops back around it says please enter a string but then never pauses to allow the user to enter anything, and so then it just saves sentence as an empty character array... it is not going around again with the same string as last time.
when i used cin >> sentence it would only save about 3 chars of the string, which was "i hope this works".
thanks for the suggestions... i'm still haven't trouble tho, if someone could please put my code into their compiler and then go from there so they can see what i'm talking about i'd really really appreciate it.
the reason the program wont let you enter a number the second time is because it dosen't pause to allow them to enter a input so what you need to do is pause it either with system("pause");
which leaves a nasty massage
or cin.get();
which leaves off the first letter
if you know how to make a invisible pause or make it so the cin.get(); dosen't get rid of the first letter