# Returning Values ## Questions 1. What is the value of `cubeByVolume(9)`? 1. 9^3 = 729. 2. What is the value of `cubeByVolume(cubeByVolume(2))`? a. `cubeByVolume(8)` = 512. 3. Using the `pow()` function, write an alternate implementation of the `cubeByVolume` function. ``` double cubeByVolume(double sideLength) { return pow(sideLength, 3.0); } ``` 4. Define a function called `squareArea` that computes the area of a square of a given `sideLength`. ``` double squareArea(double sideLength) { return pow(sideLength, 2.0); } ``` 5. Consider this function: ``` int mystery( int x, int y) { double result = (x + y ) / ( y - x); return result; } ``` What is the result of `mystery(2,3)` and `mystery(3,5)`. a. 5 and 4. 6. Implement a function that returns the minimum of three values. ``` // Prototype int findTheSmallest(int, int, int); // Implementation int findTheSmallest(int x, int y, int z) { if (x < y && x < z) { return x; } else if (y < x && y < z) { return y; } return z; } // Function call findTheSmallest(1,2,3); // => 1 ``` ## Attached Code ``` #include #include using namespace std; double steinbergPow( double, double); int main() { double result1; double result2; result1 = pow( 2.0, 4.0 ); result2 = steinbergPow( 2.0, 4.0 ); cout << "pow: " << result1 << endl; cout << "steinbergPow: " << result2 << endl; cout << endl; system("pause"); return EXIT_SUCCESS; } /** Raises base to the power @param base is the base @param power is the exponent */ double steinbergPow( double base, double power ) { double sum = 1; for( int i = 0; i < power ; i++ ) { sum = sum * base; } return sum; } /* Computes the volume of a cube. @param sideLength the side length of a cube @return the volume */ double cubeByVolume( double sideLength ) { double volume = sideLength * sideLength * sideLength; return volume; } ```