Use of Functions in Calculations

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 #define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>

using namespace 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;
	

}
Move this outside of the main function
1
2
3
4
5
//volumeCalculation Function
	double volumeCalculation(double radiusSphere)// and loose this semicolon;
	{
	volumeSphere = (4*M_PI*(pow(radiusSphere,3)/3));
	}
Hello there.

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
Thank you very much for your help, admkrk and Locien. I have fixed the issue. I appreciate it.

Your English is fine Locien, don't worry =)
Topic archived. No new replies allowed.