/* testfunc09.cpp CIS 150 6/9/2005 David Klick This program demonstrates function overloading. */ #include using std::cout; using std::cin; int getInt(); int getInt(char* prompt); int getInt(char* prompt, int min, int max); int main(void) { cout << "You entered: " << getInt() << '\n'; cout << "You entered: " << getInt("Enter an integer: ") << '\n'; cout << "You entered: " << getInt("Enter an integer (10-20): ", 10, 20) << '\n'; return 0; } /* Prompts user for integer and returns value entered. */ int getInt() { int num; cout << "Please enter an integer: "; cin >> num; return num; } /* Prompts user for integer and returns value entered. */ int getInt(char* msg) { int num; cout << msg; cin >> num; return num; } /* Prompts user for integer, does data validation, and returns value entered. */ int getInt(char* msg, int min, int max) { int num; do { cout << msg; cin >> num; if (num < min) cout << "Error: value below minimum allowed\n"; else if (num > max) cout << "Error: value above maximum allowed\n"; } while (nummax); return num; } /* Sample output: Please enter an integer: -30 You entered: -30 Enter an integer: -30 You entered: -30 Enter an integer (10-20): -30 Error: value below minimum allowed Enter an integer (10-20): 100 Error: value above maximum allowed Enter an integer (10-20): 17 You entered: 17 */