
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>


//
//  Get a string [str] of length maxLength
//  
void getString(char * query, char * str, int maxLength)
{
	cout << query;								// ask query
	
	cin >> ws;									// remove all the white spaces
	cin.getline(str, maxLength);				// read characters until \n MAXSTR
}

    //char mPalindrome[MAXSTR];     // string for Palindrome
    //
    // // input Palindrome
	// cout << "Test a Palindrome: ";
	//
    // //read characters from stdin until a newline
    // //or MAXSTR characters have been read
    // cin.getline(mPalindrome,MAXSTR);
    
    
    

//
//  reads an integer from the keyboard,
//  uses error checking to ensure value is between minValue and maxValue
//
int getInt(char askStr[], int minValue, int maxValue)
{
	int mVar;
	bool inputOK = false;
	
	while (! inputOK) { 
	
		cout << askStr;						// ask query
		cin >> mVar;						// get input
		
		if ( (mVar >= minValue && mVar <= maxValue) )
			inputOK = true;					// input OK, exit loop
		else {
			cout << "Bad input: please enter a value between "
			     << minValue << " and " << maxValue << endl;
			cin.clear();					// clear error   cin.fail(); ??
			cin.ignore(80, '\n');			// empty buffer
		}
	}
	
	return mVar;
}


//
// write digit
void writeDigit (int n)
{
	switch(n)
	{
		case 0:  cout << '0'; break;
		case 1:  cout << '1'; break;
		case 2:  cout << '2'; break;
		case 3:  cout << '3'; break;
		case 4:  cout << '4'; break;
		case 5:  cout << '5'; break;
		case 6:  cout << '6'; break;
		case 7:  cout << '7'; break;
		case 8:  cout << '8'; break;
		case 9:  cout << '9'; break;
		case 10: cout << 'A'; break;
		case 11: cout << 'B'; break;
		case 12: cout << 'C'; break;
		case 13: cout << 'D'; break;
		case 14: cout << 'D'; break;
		case 15: cout << 'F'; break;
	}
	// ...or cout << char( n + '0' )
}


//
// convert base
void writeBase(int n, int base)
{
	if (n >= base) {
		writeBase( (n / base) , base );
	}
	
	writeDigit ( n % base );
}


//
// random seed according to time
//
void randomizer()
{
	time_t      timeval;
	
	time(&timeval);
	srand(timeval);
}


//
// Random generator
//
int randomInt(int min, int max)
{
	static bool seed = false;
	int range = (max+1) - min;
	    
	if (! seed) {
		randomizer();
		seed = true;
	}
	
    return (int) (( rand() / (double) RAND_MAX ) * range + min);
}


