#include <iostream>
#include <limits>
using std::cout;
using std::cin;
using std::endl;
int getVar(int num);
int getInt(int num);
int main(){
int n;
cout<<"Insira um inteiro. \n\n";
getInt(n);
return 0 ;
}
int getInt(int n){
cin>>n;
return getVar(n);
}
int getVar(int num){
if(!(cin>> num && !num % 2 == 0)){
cout<< num <<" Entrada nao corresponde ao tipo de variavel solicitado.\n\n";
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
getInt(num);
}
else{
cin.clear();
cout<<"\n"<< num <<" Entrada recebida com sucesso!!! \n";
return num;
}
}
When I type a number that is accepted by the function, in the case of an integer, I have to type it twice in order for it to be fetched, I would like it to capture the direct input on the first attempt.