While Loop-Programming Running Constantly

I have the following program to computer volume and surface area of a sphere, cylinder, and cone. If I choose to the get the volume of any of the three shapes it would fine but when I choose to get the surface area it runs constantly. I cannot figure out why it won't work with the surface areas. Please 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
//

#include <iostream>
#include <cmath>
#include <string>
using namespace std;


inline double sphere_volume (double r)
{
	return (4.0/3.0) * 3.14159 * pow(r, 3);
}

inline double sphere_surface_area(double surface_area, double r)
{
	surface_area = 4 * 3.14159 * pow(r, 2);
	return surface_area;
}

inline double cylinder_volume(double r, double h)
{
	return 3.14159 * pow(r, 2) * h;
}

inline double cylinder_surface_area(double r, double h)
{
	return 2 * 3.14159 * pow(r, 2) + 2 * 3.14159 * r * h;
}

inline double cone_volume(double r, double h)
{
	return (1.0/3.0) * 3.14159 * pow(r, 2) * h;
}

inline double cone_surface_area(double r, double h)
{
	return 3.14159 * pow(r, 2) + 3.14159 * r * sqrt(pow(r, 2) +pow(h, 2));
}

int main()
{
	double r = 0.0;
	double h = 0.0;
	string selection = "";
	string computation = "";

	while ( selection != "q")
	{
		
			cout << "Select a shape(sphere, cylinder, cone or quit): ";
			cin >> selection;
			
			if (selection == "q")
				break;
	
			
			cout << "Select computation(volume or surface area): ";
			cin >> computation;

	

	if (selection == "sphere" && computation == "volume")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Volume of the sphere is: " << sphere_volume(r) << endl;
	}
	else if (selection == "sphere" && computation == "surface area")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Surface area of the sphere is: " << sphere_surface_area(r, h) << endl;
	}
	else if (selection == "cylinder" && computation =="volume")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Enter the height: ";
		cin >> h;
		cout << "Volume of the cylinder is: " << cylinder_volume(r, h) << endl;
	}
	else if (selection == "cylinder" && computation == "surface area")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Enter the height: ";
		cin >> h;
		cout << "Surface area of the cylinder is: " << cylinder_surface_area(r, h) << endl;
	}
	else if (selection == "cone" && computation == "volume")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Enter the height: ";
		cin >>h;
		cout << "Volume of the cone is: " << cone_volume(r, h) << endl;
	}
	else if (selection == "cone" && computation == "surface area")
	{
		cout << "Enter the radius: ";
		cin >> r;
		cout << "Enter the height: ";
		cin >> h;
		cout << "Surface area of the cone is: " << cone_surface_area(r, h) << endl;
	}
	else
	{
		cout << "Invalid entry!" << endl;
	}
	}
	system("pause");
	return 0;
}
Topic archived. No new replies allowed.