returning a value from a fuction

closed account (37poizwU)
Here is the problem: Write a program that uses a void-function called FindCylinderVol that has as an argument an integer h, which represents the height of the cylinder, and a float r, representing the radius. This function will read in a radius from the keyboard, and calculate and return the radius and the volume of a right circular cylinder, given the following equation: vol

Vol = PI * radius^2 * height.


Herer is what I came up with :

#include<iostream>
#include<iomanip>

using namespace std;

voidFindcylinderVol(float);


int main()

{
float radius, vol;

int height;
cons double PI = 3.14159;

cout << " Enter in height\n";

cin >> height;

cout << " Enter in radius\n";
cin >> radius;

voidFindCylinderVol(float r)

{

retuen PI * radius * radius * height;

}

My program not compling, can anyone add some input on what I should do or where I went wrong. Thanks.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
using namespace std;
float findCylinderVol(float, float); // can't be void if returning a value / keeping capitalization consistant
int main() {
    float radius, vol, height;
    cout << " Enter in height\n";
    cin >> height;
    cout << " Enter in radius\n";
    cin >> radius;
    vol = findCylinderVol(radius, height);
} // end of main
float findCylinderVol(float r, float h) {
    return 3.14159f * r * r * h; // typo / height is out of scope so it must be passed
}
Last edited on
closed account (37poizwU)
thanks!, Gumbercules
Topic archived. No new replies allowed.