Function definition: Volume of a pyramid.

Im not asking for an answer. Would just need a small detailed explanation of what I would need to code this program.

Define a function PyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations:

Volume = base area x height x 1/3

Base area = base length x base width.
______________________________________________________________________________

#include <iostream>
using namespace std;

double PyramidVolume(double baseLength, double baseWidth, double pyramidHeight);


int main() {
cout << "Volume for 1.0, 1.0, 1.0 is: " << PyramidVolume(1.0, 1.0, 1.0) << endl;
return 0;
}
The PyramidVolume function is already declared. Your task is to define it.

To turn the declaration on line 4 into a definition you remove the semicolon at the end and replace it with a pair of curly brackets { }. Next step will be to put the code for the function, as described, inside the curly brackets.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

double PyramidVolume(double, double, double);

int main()
{
    std::cout << "Volume for 1.0, 1.0, 1.0 is: " << PyramidVolume(1.0, 1.0, 1.0) << std::endl;
    return 0;
} 

double PyramidVolume(double length, double width, double height)
{
    return length * width * height / 3;
}
Topic archived. No new replies allowed.