/* testfunc02.cpp CIS 150 2008-06-10 David Klick This program demonstrates how to create and call a function that has an argument. */ #include #include using std::cin; using std::cout; using std::endl; using std::fixed; using std::setprecision; void display(double x); // function prototype void cont(); int main(int argc, char* argv[]) { double num = 9.87654321; display(num); // call function using variable display(5.5555); // call function using value display(2.0/3.0); // call function using expression cont(); return 0; } /* void display(double d); Arguments: double d: a value to be displayed on stdout with two digits after the decimal point Returns: nothing This function displays a double in fixed format with two digits after the decimal point. */ void display(double d) { cout << fixed << setprecision(2) << d << endl; return; // optional since no value is returned } /* 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(); }