/* testpointer2.cpp CIS 150 David Klick 6/26/08 Passing a pointer to a function. */ #include using std::cin; using std::cout; void cont(); void getnum(const char* prompt, int* p); int main() { int n; getnum("Enter an integer: ", &n); cout << "You entered " << n << '\n'; cont(); return 0; } /* void getnum(const char* prompt, int* p); Arguments: const char* prompt: prompt to display to user int* p: address where user input will be stored Returns: Nothing, but alters the value at *p. Displays prompt and waits for user to enter an integer. The value is then stored in the location pointed to by the second argument. */ void getnum(const char* prompt, int* p) { int val; // get integer from user cout << prompt; cin >> val; // store value where calling program requested *p = val; } /* void cont(); Arguments: none Returns: nothing Clears input buffer and pauses waiting for user to press Enter. */ void cont() { if (cin.rdbuf()->sungetc() != -1 && cin.get() != '\n') cin.ignore(80,'\n'); cout << "Press enter to continue..."; cin.get(); }