c++ - repeat code automatically -


i wrote code convert string morse code. code works perfect until try repeating automatically.

whether use "while" or "do while" code runs once , terminates. find out problem is?

int main () {     cout<<"enter string: ";     char mystr[81];     char ch='y';      while (ch=='y'||ch=='y')     {         getstring(mystr);         toupper(mystr,strlen(mystr));         removespace(mystr);         getmorse(mystr,strlen(mystr));         cout<<"to repeat press y/y";         cin>>ch;     }     return 0; } 

i added getstring() function

void getstring(char mystr[]) {   cin.getline(mystr,81,'\n'); } 

after user enters input, press enter. newline character '\n' still in cin stream. need ignore it:

cin >> ch; cin.ignore(numeric_limits<streamsize>::max(), '\n'); //this ignores subsequent characters until newline character 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -