Please tell me how bad this code segment is. I figured I would share this horrible code. If it's not as horrible as I think it is, please let me know. Thanks!
/*
Purpose: Create a function to check the input from user. Only valid integer should be returned. All other input should be tossed, user should be asked again for valid integer input.
Name: Saith
Date: 6/4/11
*/
#include<iostream>
using namespace std;
int ReturnChosenNumber();
int main(){
int number = ReturnChosenNumber();
cout << number;
return 0;
}
int ReturnChosenNumber(){
// A very ghetto function. Enjoy the scrap work, make shift. integer checker :D
int number;
cin >> number;
while(cin.fail() ){
cin.clear();
cin.ignore(1000,'\n');
cout << "Input not an integer value. Try again.\n";
number = ReturnChosenNumber();
}
return number;
}
Edit: I changed from using SStream, String, to just cin. The older version used them, but decided cin was just as good.