Untested...
#include <iostream>
#include <string>
#include <sstream>
#include <limits>
using namespace std;
class Crap
{
public:
bool myCheck(string var)
{
int counter = 0;
int s = var.length();
for ( int i = 0; i < s; i++ )
{
if ( isNumber(var[i]) == true )
{
counter = counter + 1;
}
}
if ( ( counter == s ) && ( var[0] != '0' ) )
return true;
else
return false;
}
bool isNumber( char ch )
{
if ((ch >= '0') && (ch <= '9'))
return true;
else
return false;
}
};
int main()
{
string input;
Crap foo;
do
{
cout << "Enter a number ugly:";
getline ( cin, input, '\n' );
if ( foo.myCheck( input ) == true )
{
cout << "That's a number" << endl;
//use stringstream to convert to
//integer
}
else
cout << "Ain't no number" << endl;
}while ( foo.myCheck( input ) != true );
return 0;
}
Maybe you could use limits as well. By number I assume you mean integer ( whole number)