0

I wanted to create a do while loop, that if the user wants to repeat the action, the program starts again, however after the program is supposed to repeat, the 1. getlin(cin, string) gets irgnored. The 2. getline(cin, string) works fine. It's a calculator that solves terms being put in by the User via getline(cin,string).

 do
{

    cout << "Please enter a term: ";
    getline(cin, s);                   //This gets ignored once repeated
    while( correctTerm(s) == 0)
     {
        cout << "Please only use allowed characters: " ;
        getline(cin,s);                  //This works fine
     }
    term = split(s, ' ');                //splits string into a vector
    cout << calculate(term) << endl;    //prints the answer to the term
    cout << "Do you want to enter a new term?(Y/N)";
    cin >> answer;                   //This works too

}
while(answer == 'Y');
  • The `cin >> answer` line leaves a newline character in the input buffer, which will cause the next `getlne()` call to return immediately. Looking for a good duplicate... – Adrian Mole Feb 08 '21 at 11:28

0 Answers0