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;
}
}
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?
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.