UMBC CMSC 201 Fall '05 CSEE | 201 | 201 F'05 | lectures | news | help |
The American Heritage Dictionary of the English Language defines a module as follows:
/*********************************************************************** * * GetValidInt(min,max) reads integers from the user until one between * min and max (inclusive) is entered, reprompting the user in * response to bad ones. The eventual ggood value is returned. * * INPUTS: min and max, the minimum and maximum (inclusive) values for * the entered integer * OUTPUT: an integer between min and max (inclusive) * **********************************************************************/ int GetValidInt(int min, int max) { /* is set greater than max so the loop will be entered*/ int input = max + 1; /* Loop assures a valid entry */ while( input < min || input > max ) { printf("Please enter an integer between"); printf(" %d and %d : ", min, max); scanf("%d", &input); } return input; }