C++ askToDoAgain() gets wrong user input -


i'm making basic todo application in console c++.

in menu asked options: 1. add todo 2. remove todo 3. show todos 4. exit application

after option asked turn menu, or action again. works fine add todo , show todo. after removing todo, asktodoagain() function gets executed twice. first time, outputs question , nothing more, , second time asks input removetodo() function gets executed no matter if choose go menu.

screenshot of problem

those removetodo() , asktodoagain() function:

void ftodo::removetodo() {     int removedtodo;     int index = 0;      std::cout << "your option is: [2] remove todo" << std::endl;      // loop on every item in array     each (string todo in todos)     {         std::cout << "[" << index << "] " << todo << std::endl;         index++;     }      // ask todo user wants delete     std::cout << std::endl << "type number of todo want delete: ";     std::cin >> removedtodo;      // remove part of array     todos.erase(todos.begin() + removedtodo);      return; }  bool ftodo::asktodoagain() {     string response;      std::cout << std::endl << "do want go menu? (y/n) ";      std::getline(std::cin, response);     std::cout << std::endl;      if (response != "y" && response != "y" && response != "n" && response != "n")     {         asktodoagain();     }      if (response == "y" || response == "y") {         return false;     }      return true; } 

this selectoption() function:

void selectoption() {     int currentoption = todo.getcurrentoption();      // select option based on currentoption     switch (currentoption)     {     case 1:         todo.addtodo();         break;     case 2:         todo.removetodo();         break;     case 3:         todo.showtodo();         break;     case 4:         std::cout << "leaving..." << std::endl;         exit(1);         break;     default:         break;     }      // ask same option again     if (todo.asktodoagain() == true) {         selectoption();     }     else {         main();     } 

thanks helping me! ;)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -