#include <iostream>
using namespace std;
int ActionGenerator() {
int Action;
while(true) {
cout << endl << "SELECIONE UMA ACTION: " << endl;
cout << "[1 = ActionX]" << endl << "[2 = ActionZ]" << endl;
cin >> Action;
if (Action == 1 || Action == 2) return Action;
else {
cout << endl << "ACTION INVALIDA !" << endl;
cin.clear(); //Limpa a flag de erro quando há falha no parse do valor entrado
cin.ignore(); //Limpa o buffer
}
}
}
int main() {
cout << ActionGenerator() << endl << "ok" <<endl;
}
//https://pt.stackoverflow.com/q/41855/101
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IEFjdGlvbkdlbmVyYXRvcigpIHsKICAgIGludCBBY3Rpb247CiAgICB3aGlsZSh0cnVlKSB7CiAgICAgICAgY291dCA8PCBlbmRsIDw8ICJTRUxFQ0lPTkUgVU1BIEFDVElPTjogIiA8PCBlbmRsOwogICAgICAgIGNvdXQgPDwgIlsxID0gQWN0aW9uWF0iIDw8IGVuZGwgPDwgIlsyID0gQWN0aW9uWl0iIDw8IGVuZGw7CiAgICAgICAgY2luID4+IEFjdGlvbjsKICAgICAgICBpZiAoQWN0aW9uID09IDEgfHwgQWN0aW9uID09IDIpIHJldHVybiBBY3Rpb247CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIGNvdXQgPDwgZW5kbCA8PCAiQUNUSU9OIElOVkFMSURBICEiIDw8IGVuZGw7CiAgICAgICAgICAgIGNpbi5jbGVhcigpOyAvL0xpbXBhIGEgZmxhZyBkZSBlcnJvIHF1YW5kbyBow6EgZmFsaGEgbm8gcGFyc2UgZG8gdmFsb3IgZW50cmFkbwogICAgICAgICAgICBjaW4uaWdub3JlKCk7IC8vTGltcGEgbyBidWZmZXIKICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgY291dCA8PCBBY3Rpb25HZW5lcmF0b3IoKSA8PCBlbmRsIDw8ICJvayIgPDxlbmRsOwp9CgovL2h0dHBzOi8vcHQuc3RhY2tvdmVyZmxvdy5jb20vcS80MTg1NS8xMDE=