This code defines two functions Volume
and Surface
that calculate the volume and surface area of a cube, respectively. The main
function prompts the user to enter the length of an edge of a cube, which is stored in a variable edgeLength
. Then, the Volume
and Surface
functions are called with edgeLength
as their argument, and the results are displayed to the user.
This program can be compiled and run, and it will correctly display the volume and surface area of a cube with the specified edge length.
#include <iostream>
using namespace std;
double Volume (double a) {
double volume;
volume = a * a * a;
return volume;
}
double Surface (double a) {
double surface;
surface = 6 * a * a;
return surface;
}
int main () {
double edgeLength;
cout << "Please enter the edge length: " << endl;
cin >> edgeLength;
cout << "Volume: " << Volume(edgeLength) << endl;
cout << "Surface: " << Surface(edgeLength) << endl;
return 0;
}
Please enter the edge length:
5
Volume: 125
Surface: 150