I can't compile this for this reason:

error C4700: uninitialized local variable 'h' used
error C4700: uninitialized local variable 'R1' used
error C4700: uninitialized local variable 'R2' used

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 /*
03-09-2015
This Program will read input values of two radius values R1 and R2, and height
It will then compute volume and return it as well as the surface area's volume 
It will finally display volume and surface values as output to the user.
*/

#include <iostream>
#include <cmath> //math library function
using namespace std;


int main()
{
	// Declare variables
	double h, R1, R2, vol, surf;

	// Volume will accept three variables as inputs: R1, R2, and h 
	double volume(double R1, double R2, double h);

	// Define Pi
	double pi = 3.14;

	// Equation for volume of a cone 
	double V = (1 / 3)*pi*h*(pow(R1, 2) + (pow(R2, 2) + R1*R2));


	// Surface will accept three variables as inputs: R1, R2, and h
	double surface(double R1, double R2, double h);
	{
		double pi = 3.14;

		// Equation for surface area of cone 
		double S = pi*(R1 + R2)*sqrt(pow(R2 - R1, 2) + pow(h, 2)) + pi*pow(R1, 2);

	}


	// Prompt and read input values of radius (R1,R2)
	cout << " Please enter the radius value(R1): ";
	cin >> R1;
	
	cout << " Please enter the radius value(R2): ";
	cin >> R2;

	cout << " Please enter the heigh of cone(h): ";
	cin >> h;

	// Define the functions

	vol = volume(R1, R2, h);
	surf = surface(R1, R2, h);

	// Display outputs 
	cout << " The volume of the cone= " << vol << endl;

	cout << " The surface area of the cone= " << surf << endl;

	system(" PAUSE ");

}

Do not declare functions inside function main().

Line 19 is a function declaration. Move it before line 13.
Line 29 is a function declaration. Move it before line 13.

The brace-enclosed block on lines 30-36. Is it supposed to be implementation of function "surface"? Syntactically it is not, because (a) it is inside scope of main() and (b) line 29 ends with semi-colon.


The compiler errors do tell the filename and linenumber. That is useful information that you did omit. I do guess that they all three point to line 25, where you use their values, although you did not initialize the values during variable declaration on line 16 nor have set them since.
I have rewrote the code as you said, but now i'm getting the error that " 'pi': redefinition; multiple initialization"

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
47
48
49
50
51
52
53
54
55
56


#include <iostream>
#include <cmath> //math library function
using namespace std;

// Volume will accept three variables as inputs: R1, R2, and h 
double volume(double R1, double R2, double h);

// Surface will accept three variables as inputs: R1, R2, and h
double surface(double R1, double R2, double h);



int main()
{
	// Declare variables
	double h, R1, R2, vol, surf;

	// Define Pi
	double pi = 3.14;

	// Equation for volume of a cone 
	double V = (1 / 3)*pi*h*(pow(R1, 2) + (pow(R2, 2) + R1*R2));

	double pi = 3.14;

	// Equation for surface area of cone 
	double S = pi*(R1 + R2)*sqrt(pow(R2 - R1, 2) + pow(h, 2)) + pi*pow(R1, 2);

	


	// Prompt and read input values of radius (R1,R2)
	cout << " Please enter the radius value(R1): ";
	cin >> R1;

	cout << " Please enter the radius value(R2): ";
	cin >> R2;

	cout << " Please enter the height of cone(h): ";
	cin >> h;

	// Define the functions

	vol = volume(R1, R2, h);
	surf = surface(R1, R2, h);

	// Display outputs 
	cout << " The volume of the cone= " << vol << endl;

	cout << " The surface area of the cone= " << surf << endl;

	system(" PAUSE ");

}
Let me write one possible main() for you:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
int main()
{
  using std::cout;
  using std::cin;
  // Declare variables
  auto R1 = 0.0;
  auto R2 = 0.0;
  auto h = 0.0;
  // Prompt and read input values of radius (R1,R2)
  cout << " Please enter the radius value(R1): ";
  cin >> R1;
  cout << " Please enter the radius value(R2): ";
  cin >> R2;
  cout << " Please enter the height of cone(h): ";
  cin >> h;
  // calculate
  auto vol  =  volume( R1, R2, h );
  auto surf = surface( R1, R2, h );
  // Display outputs
  cout << " The volume of the cone= " << vol << '\n';
  cout << " The surface area of the cone= " << surf << std::endl;
  return 0;
}

Now your task is to write the implementations for the two functions.


Note: (1/3) == 0 but (1.0/3) is about 0.333
Topic archived. No new replies allowed.