so I have been learning C++ and was working on a monkey see monkey do program and i managed to get the first input working but the second input it just skips straight over it, i have no clue why and any help would be apreciated.
#include <iostream> #include <string> using namespace std; char monkey_1; char monkey_2; int msmd() { cout << "monkey one:"; cout << endl; cin >> monkey_1; system("cls"); cout << "monkey two:"; cout << endl; cin.clear(); cin >> monkey_2; cout << "waiting"; cout << endl; if (monkey_1 == monkey_2) { cout << "both monkeys are happy."; cout << endl; } else { cout << "the monkeys are upest."; cout << endl; } return 0; } void main() { msmd(); }
cin.clear()BTW - that clears any error conditions on thecinstream, and there's no reason to think you'd have any.)mainmust returnint.cinalready has characters available. The next character that you typed will get assigned to monkey_2.characcepts a single character, and>>skip whitespace, so if you've typed something like "jump" and pressed ENTER, it'll readjintomonkey_1anduintomonkey_2without waiting for more text or another press of ENTER. Same if you typedjSPACEuENTER.)