/* testfunc12.cpp CIS 150 2008-06-10 David Klick Passing arguments by reference. */ #include using std::cin; using std::cout; void getDimensions(double &height, double &width); void cont(); int main(int argc, char* argv[]) { double h, w; // height and width cout << "Rectangle area calculator\n"; getDimensions(h, w); cout << "The area is " << (h*w) << '\n'; cont(); return 0; } /* void getDimensions(double &height, double &width); Arguments: double &height: a ref var where the height will be stored double &width: a ref var where the width will be stored Returns: nothing (but note that the height and width entered by the user are stored in the reference variables passed in as arguments Gets height and width from user. */ void getDimensions(double &height, double &width) { // get height do { cout << "Enter height: "; cin >> height; if (height < 0.0) cout << "Error: height must be positive\n"; } while (height < 0.0); // get width do { cout << "Enter width: "; cin >> width; if (width < 0.0) cout << "Error: width must be positive\n"; } while (width < 0.0); } /* 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(); }