Hi All
see my explanation about recursion
herea better way to go would be:
CODE
/*
Project Software Engineer
Mr Gregory Hicks BIT
Sydney Australia
(C) 2006
This code may be used provided
credit is given for the source
*/
#include <cstdlib>
#include <iostream>
using namespace std;
int getUserInput ( const char* msg , const int min , const int max , const int quit );
char getUserInput ( const char* msg , const char min , const char max , const char quit );
int main(int argc, char *argv[])
{
int t = getUserInput ( "Enter an integer" , 0 , 10 , -1 );
if ( t != -1 )
cout << " Integer entered is: " << t << endl;
char c = getUserInput ( "Enter a letter" , 'A' , 'z' , '0' );
if ( c!= '0' )
cout << "Letter entered is: " << c << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
/*
Purpose: To get an integer input from the user
Accepts: msg - display message
Min - smallest acceptable value
Max - largest acceptable value
quit - vaue to force quit on return
*/
int getUserInput ( const char* msg , const int min , const int max , const int quit )
{
int input;
do {
cout << msg << " (Range: " << min << " to " << max << " , quit= " << quit << "): ";
cin >> input;
} while ( input != quit && ( input < min || input > max ) );
return input;
}
/*
Purpose: To get a char input from the user
Accepts: msg - display message
Min - smallest acceptable value
Max - largest acceptable value
quit - vaue to force quit on return
*/
char getUserInput ( const char* msg , const char min , const char max , const char quit )
{
char input;
do {
cout << msg << " (Range: " << min << " to " << max << " , quit= " << quit << "): ";
cin >> input;
} while ( input != quit && ( input < min || input > max ) );
return input;
}
This post has been edited by gregoryH: 13 Oct, 2006 - 07:06 PM