Trouble with a program

I'm supposed to make one program that calculates the volume of a cone from the user input of a height and radius. It's also supposed to call a function to do this, and ask if they want to enter another value. If they say "N" it breaks.
I am getting an error that says undefined reference to volumef(). Here's my code
Thanks for any help in advance :D

#include <iostream>
#include <cmath>
#define PI 3.14159
#include <string>
using namespace std;
double volumef();
double vol, radius, height;
string con;

int main ()

{



cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<" Program by me "<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;

while (true)
{
cout<<"Enter a Radius: "<<endl;
cin>>radius;
cout<<"Enter a Height: "<<endl;
cin>>height;
vol=volumef();
cout<<"The volume is "<<vol<<endl;
cout<<" Do you want to enter another value? (Y/N)"<<endl;
cin>>con;
if ("con"=="N")
{
break;
}
}

system("pause");
return 0;
}

double volumef(double radius, double height)
{
double vol;
vol=1/3*PI*radius*radius*height;
return vol;
}
//end function
In C++, the compiler must know about a function before you try to use it. You can do this in one of two ways:

1) Move your definition of the function in question above the main function.
2) Declare the function ahead of use, with a prototype double volumef(double radius, double height);

You have attempted to do method 2, but you've got the prototype wrong. You used
double volumef(); which is the prototype for a function named volumef that returns a double and takes in no parameters, whereas your actual function volumef takes in two double parameters.

As an aside, if ("con"=="N")? Why are there quote marks around con?

Edit; NinjaTASTIC! :)
Last edited on
Please put your code inside code tags [code] [/code] to make your code easier to read and increase the your chances to get helped.

double volumef(double, double) is not the same function as double volumef().
you declare volume having two parameters, but call the function with zero. The compiler takes this as function overloading and looks for a volumef() function with no parameters, which is non-existent.
 
vol=volumef(); // no parameters 


what it should be:
 
vol=volumef(radius,height);
Moschops wrote:
Edit; NinjaTASTIC! :)

Your answer is best so it deserves being first.
Thank you for your replies!
The program works now but it is giving me a volume of 0 for any input
1/3 Both operands are integers so it will do integer division. The result is 0 so the whole expression will also be 0.
Topic archived. No new replies allowed.