/* demoFunc.cpp Dave Klick CIS 150 2018-02-27 Demonstrates functions */ #include #include using namespace std; void display(string msg); void display(int num, string msg); int factorial(int n); double calcArea(double len, double wid); double getDouble(string prompt, double min, double max); int main() { double length, width; display("It's a great night tonight!"); display(4, "Sometimes I stutter."); cout << "5! is " << factorial(5) << endl; length = getDouble("Enter the length (1-35): ", 1, 35); width = getDouble("Enter the width (5-25): ", 5, 25); cout << "The area is " << calcArea(length, width) << endl; return 0; } void display(string msg) { cout << msg << endl; } void display(int num, string msg) { for (int i=1; i<=num; i++) { cout << msg << endl; } } int factorial(int n) { int prod = 1; for (int i=1; i<=n; i++) { prod = prod * i; } return prod; } double calcArea(double len, double wid) { return len * wid; } double getDouble(string prompt, double min, double max) { double num; cout << prompt; cin >> num; while (num < min || num > max) { cout << "Number out of range\n"; cout << prompt; cin >> num; } return num; }