Call functions c++ (recursion and CIN input) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Call functions c++ (recursion and CIN input)

Why when I call @choosingAction@ function again I have not an offer to input some information by CIN? void choosingAction(list* &header, list* &tail) { int choose, age; string name; cin >> choose; switch (choose) { case(1): cout << "Input name and age:" << endl; cin >> name >> age; addNode(header, tail); choosingAction(header,tail); break; case(2): cout << 2; break; default: cout << "Incorrect operation, please choose again" << endl << "| Add - 1 | Find - 2 |" << endl; choosingAction(header,tail); } }

23rd Mar 2019, 9:30 AM
coding-space.ru
coding-space.ru - avatar
3 Answers
+ 3
Code Playground does not provide an interactive console. All input has to be received prior to code compilation. If you wish to run your code, try repl.it, or codechef, or cpp.sh.
23rd Mar 2019, 9:35 AM
Fermi
Fermi - avatar
+ 2
The problem isn't reproducible. It works well on VS and g++ with some modification (changing the type of the arguments to some primitive type). The best guess is, probably there was some left over on the stream from your previous inputted data, therefore, the next prompt got skipped. Using the `std::cin ` without safety functions like `std::cin.ignore()` and `std::cin.clear()` in such cases exposes the input mechanics to some unexpected behaviors. There might be some other possibilities, but they are less likely and there's not enough code to consider them, as well.
23rd Mar 2019, 10:38 AM
Babak
Babak - avatar
0
ahaha, I know it. I wrote this code to you see it. I did not want to run it here
23rd Mar 2019, 9:46 AM
coding-space.ru
coding-space.ru - avatar