I need to check in my program if the user inputs an integer and not a character or string. Character isn't that bad since it's pratically an integer, but if the user enters a sequence of characters then it just goes nuts.
I've made this function
int* ask_lung(int* lung)
{
int tmp; // length of a word
cout << "Inserisci la lunghezza della parola da indovinare: ";
cin >> tmp;
if(cin)
{
// Se i è uguale a o minore di 0 allora ritorna all'inizio
if(tmp <= 0)
{
cout << endl << "\tNon puoi inserire 0." << endl << endl;
ask_lung(lung);
}
else
{
// the error is about here, when it reaches this part of the code it keeps showing the first line "Inserisci la lunghezza della parola da indovinare: "
*lung = tmp;
}
}
else ask_lung(lung);
return lung;
}