New to C++ and trying to use a custom header file for the first time. I'm receiving "undefined reference to" my functions in main()
for all of my functions when I compile so i'm assuming i'm missing a piece of important syntax somewhere. I've looked at the docs on other posts and I haven't found an answer or a reference to something different than i'm doing. Code below is just for learning purposes I know there are some better ways to do things. Any thoughts?
Code in Main Source File Named: SixthProgram.cpp
//Write functions that will do the following:
//Get a positive integer value from the user and return that value
//Calculate the area of a circle based on a radius
//Calculate the volume of a sphere based on a radius
//
#include <iostream>
#include <string>
#include "MyMathFunctions.h"
using namespace std;
int main()
{
string msgFromMain = "Please input a positive integer value: ";
int integerValueFromUser = getIntegerFromUser(msgFromMain);
double aCircle = areaOfCircle(integerValueFromUser);
double vSphere = volOfSphere(integerValueFromUser);
cout << "The area of a circle that has a radius of " << integerValueFromUser
<< " is " << aCircle << "." << endl;
cout << "The volume of a sphere that has a radius of " << integerValueFromUser
<< " is " << vSphere << "." << endl;
return 0;
}
Functions Header File Named: MyMathFunctions.h
#ifndef MYMATHFUNCTIONS_H_
#define MYMATHFUNCTIONS_H_
const double PI = 3.14159;
int getIntegerFromUser(std::string);
double areaOfCircle(int radius);
double volOfSphere(int r);
#endif
Functions Source File Named: MyMathFunctions.cpp
#include <iostream>
#include <string>
#include <cmath>
#include "MyMathFunctions.h"
using namespace std;
int getIntegerFromUser(string msgFromMain)
{
//Gets integer value from client and returns value to main
int integerValueFromUser = 0;
int loopValidationCounter = 0;
do
{
cout << msgFromMain << endl;
cin >> integerValueFromUser;
if(integerValueFromUser <= 0)
{
cout << integerValueFromUser << " is not a positive integer value. Please try again: " << endl;
}
}while(integerValueFromUser <= 0);
return integerValueFromUser;
}
double areaOfCircle(int radius)
{
return PI * pow(radius,2);
}
double volOfSphere(int r)
{
return (double)(4/3.0) * PI * pow(r,3);
}