question (simple program)


My program says "volume" does not have a value when I build it. What would I enter for the volume? I'm confused.

/*
Program: repair1c - program prompts for radius and height, displays volume of cylinder
Examples:
if radius is 11.25 and height is 50, volume is 19880.438
if radius is 7.75 and height is 22.2, volume is 4188.970
Fix the function, do not change main or
change the statements already in the function
*/

#include <iostream>
#include <iomanip>
using namespace std;


double volume( double radius, double height);

int main(void)
{
double radius, height;

cout << "Enter radius and height: ";
cin >> radius >> height;

cout << fixed << setprecision(3);
cout << "The volume is: " << volume(radius, height) << endl;

return 0;
}

double volume( double radius, double height)
{
double capacity;
capacity = 3.1416 * radius * radius * height;
}
@newyork23

Just add a 'return capacity;' in the volume function, just before your closing right parenthesis. You have that function declared as a double, so it's expecting to return a result of a double. Declare an int, and it returns an int. A declared 'void', returns nothing.
http://www.cplusplus.com/forum/beginner/209101/

You are missing something that was addressed in your other question.
Topic archived. No new replies allowed.