First time with user defined functions...

This is homework, so just looking for some guidance. Program for calculating right-circular cone calculations (global variables are prohibited). I have spent around 20 hours trying to figure out what I am doing wrong. Every time a function references inputradius and inputheight functions, it prompts for input again. I have tried reordering, rearranging, rewriting, and reorganizing. Ideally I would like to pull the info from main but can't seem to pull any info from main. Any help or suggestions are appreciated. I am the quintessential beginner, so I may respond to your answer with another question. Thanks in advance.
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.14159;

double inputradius (double baseRadius)
{
 double inputRad;
 
 cout << "Enter cone radius (in meters):  ";
 cin >> inputRad;
 
 baseRadius = inputRad;
 
return baseRadius;
}

double inputheight (double coneHeight)
{

 double inputHght;

  cout << "Enter cone height (in meters):  ";
  cin >> inputHght;
  
  coneHeight = inputHght;
  
return coneHeight;
}

double slant (double slantHeight)
{
 
 double radius;
 double height;
 double r2;
 double h2;
 double baseRadius;
 double coneHeight;
 
 radius = inputradius (baseRadius);
 height = inputheight (coneHeight);
 
 
 r2 = pow (radius, 2);
 h2 = pow (height, 2);
 
 slantHeight = sqrt (r2 + h2);
 
 return slantHeight;
}
 
double area (double surfaceArea)
{

 double radius;
 double r2;
 double slantH;
 double baseRadius;
 double slantHeight;
 
 radius = inputradius (baseRadius);
 slantH = slant (slantHeight);
 
 r2 = pow (radius, 2);
 
 surfaceArea = (PI * r2) + (PI * radius * slantH);
 
 return surfaceArea;
}

double conevolume (double volume)
{

 double radius;
 double height;
 double baseRadius;
 double coneHeight;
 double r2;
  
 radius = inputradius (baseRadius);
 height = inputheight (coneHeight);
 
 r2 = pow (radius, 2);
 
 volume = (1.0 / 3.0) * PI * r2 * height;
 
 return volume;
}

double outputform ()
{
  double radius;
  double height;
  double outputVolume;
  double outputSurfaceArea;
  double baseRadius;
  double coneHeight;
  double volume;
  double surfaceArea;
  
  cout << showpoint << setprecision (2);
  
  radius = inputradius (baseRadius);
  height = inputheight (coneHeight); 
  outputVolume = conevolume (volume);
  outputSurfaceArea = area (surfaceArea);
  
  cout << "RESULTS:" << endl;
  cout << "For a cone with a radius of " << radius << " and a height of ";
  cout << height << " meters" << endl << endl;
  
  cout << "Cone Volume: " << outputVolume << " cubic meters" << endl;
  cout << "Cone Surface Area: " << setprecision (3) << outputSurfaceArea;
  cout << " square meters" << endl;
  
return 0;
}
  


int main ()
{
  double radius;
  double height;
  double baseRadius;
  double coneHeight;
  double output;
  
  cout << "Cone Calculations" << endl << endl;
     
  radius = inputradius (baseRadius);
  height = inputheight (coneHeight);
  output = outputform ();
  
  cout << endl;
   system ("PAUSE");
   return 0;
}
Last edited on
Refer here: http://www.cplusplus.com/doc/tutorial/functions/ and here: http://www.cplusplus.com/doc/tutorial/functions2/ (or your textbook/lecture notes)

how to use code tags: http://www.cplusplus.com/forum/articles/42672/

IMO, you should try to start simple e.g write a function that process a number from user and prints the result, or add two numbers etc.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//includes

void funcName( int userInput )
{
     if (userInput%2 == 0)
          std::cout << userInput << " is even " << std::endl;
     else
          std::cout << userInput << " is odd " << std::endl;
}

{
// main
     int input;
     std::cin << input;
     funcName(input);
// end main
}
Topic archived. No new replies allowed.