Hello. I'm experimenting with functions and cannot get this program to run. I'm receiving an error: fatal error LNK1120. I'd appreciate any help. Thanks
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
usingnamespace std;
double volumeCalculation(double radiusSphere);
int main(){
double volumeSphere;
double radiusSphere;
double finalRadius;
double incrementRadius;
//Request for user input values
cout << "Please input a value for the intial value of the radius (Ex Input (mm) :12 )\n";
cin >> radiusSphere;
cout << "Please input a value for the final value of the radius (Ex Input (mm) :12 )\n";
cin >> finalRadius;
cout << "Please input a value for the increment for the radius (Ex Input (mm) :12 )\n";
cin >> incrementRadius;
//volumeCalculation Function
double volumeCalculation(double radiusSphere);
{
volumeSphere = (4*M_PI*(pow(radiusSphere,3)/3));
}
//While loop - Outputs Values and uses volumeCalculation function
while (radiusSphere <= finalRadius)
{
volumeCalculation(radiusSphere);
cout << "The volume of a sphere with a radius of " << radiusSphere << " mm is " << volumeSphere << " mm3.\n";
radiusSphere = radiusSphere + incrementRadius;
}
return 0;
}
//volumeCalculation Function
double volumeCalculation(double radiusSphere)// and loose this semicolon;
{
volumeSphere = (4*M_PI*(pow(radiusSphere,3)/3));
}
1. Your function should be written outside main( after main's {} ). And semi-colon only at function prototype.
2. Your function should return a double, yet there is no return at all( return randomVariable ).
3. Your function call seems correct but you forgot to use a variable to store it's return value. You created it, but you have to use it. ;) Another option is to use the function call with that last cout in your program.
4. English is not my mother tongue, forgive any mistakes. :p