Issue with returning variables with if statments

Ive been getting an odd error with this code when I try to compile it, as well as Im not quite sure as how to return my variable "compType" as a char type.


Main
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

#include <iostream>
#include "Shape.h"
#include <iomanip>
#include <cmath>

using namespace std;



void inputShape( char shape)
{
	cout << "Select a Shape (1) sphere (2) cylinder (3) cone (q) quit: "<< endl;
	cin >> shape;

	if ( shape == SPHERE)
	{
		
		void inputDimension (double&);
		{
			double radius = 0.0;
			cout << "Enter radius: " << endl;
			cin >> radius;
	
		}

	}
	else if (shape == CYLINDER)
	{

			void inputDimension (double&, double&);
		{
			double radius = 0.0;
			cout << "Enter radius: " << endl;
			cin >> radius;

			double height = 0.0;
			cout << "Enter height: " << endl;
			cin >> height;
	
		}

		
	}
	else if (shape == CONE)
	{

		void inputDimension (double&, double&);
		{
		double radius = 0.0;
			cout << "Enter radius: " << endl;
			cin >> radius;

			double height = 0.0;
			cout << "Enter height: " << endl;
			cin >> height;
		}

	}
	else if ( shape == QUIT)
	{
		cout << "Good bye!" << endl;
	}
	else
	{
		cout << "Invalid Entry, Good bye!" << endl;
}


void inputDimension (double&);
{
	double radius = 0.0;
	cout << "Enter radius: " << endl;
	cin >> radius;
	
}


void inputDimension (double&, double&); 
{

	double radius = 0.0;
	cout << "Enter radius: " << endl;
	cin >> radius;
	
	double height = 0.0;
	cout << "Enter height: " << endl;
	cin >> height;
	
}

char inputCompType();
{
	int compType;
	cout << "Select a Computation (1) volume (2) surface area: " << endl;
	cin >> compType;

	if( compType == 1)
		compType = VOLUME;
	else if ( compType == 2)
		compType = SURFACE_AREA;

	
}


void performComputation (char, double);
{
	
	


}


void performComputation (char, char, double, double);

{


}



int main();

{
	char shape = '0';
	char compType = '0';
    double radius = 0.0;
    double height = 0.0;
   
	// Call inputShape function to request the first shape
	char inputShape();

	
     // type or ‘q’ and return result to the shape variable 

	 // Loop until the user specifies QUIT for the shape type
	
	
	
 
		// if Spheres:
	if ( inputShape() == SPHERE)
	{
		// Call the appropriate inputDimension function
		// to request the radius
		void inputDimension(double&);


		// Call the inputCompType function to request 
		// the computation type and return result to 
		// the compType variable
		char inputCompType();



		// Call the appropriate performComputation
		// function to compute and display the result
		void performComputation (char, double);



// end if Spheres 

	}	


// If Cylinders or Cones:
	 if (inputShape() == CONE || CYLINDER)
	{
		// Call the appropriate inputDimension function
		// to request the radius and height
		char inputCompType();


		// Call the inputCompType function to request 
		// the computation type and return result to 
		// the compType variable
		void inputDimension(double&, double&);

		// Call the appropriate performComputation
		// function to compute and display result

		void performComputation (char, char, double, double);

		// end if Cylinders or Cones
	}
	





	 // Call inputShape function to request the next shape 
	// type or ‘q’ and return result to the shape variable 

	 if ( inputShape() == QUIT)
	{
		cout << "Good bye!" << endl;
	}


 


     // end loop

     system("pause");
     return 0;
}



.H
1
2
3
4
5
6
7
8
9
const double PI = 3.141593;
const char SPHERE = '1';
const char CYLINDER = '2';
const char CONE = '3';
const char QUIT = 'q';
const char VOLUME = '1';
const char SURFACE_AREA = '2';

Well there is a fair amount of issues I see here. So I will start off with any time your say double& when you actually mean

1
2
3
4
5
6
7
8
9
10
11

void someFunction (double& something) {
something = 1; 
} 

int main () {
double something; 
someFunction (something); 
cout << something; 
return 0; 
} 


and the output if I remember this stuff correctly should be 1;

This being said passing a reference when it is a double or a int is pretty much pointless as passing copies takes up just as much time/memory as pointers to int and so forth.

The second thing is if you write a function don't keep rewritting it like at line 31, 48. You rewrote a function that already exists all you had to do was write a function prototype above input shape. Like so...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
#include <libraries> 
using namespace std; 

void inputDimension (double something, double otherthing)

// then  in your inputshape function
if ( shape == SPHERE)
	{
		
		void inputDimension (double something, double otherThing); // this is all you need to use this function. 
		

	}


Also, don't change number of function arguments if inputDimension calls for two arguments then input two arguments. Otherwise, you have a different function or you can pass a hard coded argument and then ignore it. I point this out because you do so in line 19 where is should be similar to line 31 or write a different function with a different name that only uses one function argument. Yes, that statement is also direction at your two different performComputation functions...

Furthermore, I don't understand why you are using 1 as a char just keep as an int your making it harder on yourself.

Also, there are some problems in your main, for example:

1
2
 
char inputShape();


Quite simply this is error. Perhaps you might to have
1
2
3

char returnedStatement = inputShape()


However, you would have to change your type.

This is the same problem with your if statements such as
1
2
 
if ( inputShape() == SPHERE)


Your trying to make a comparison between a char and a void function. This also needs to changed.

Now to the question you were probably looking it depends on the point of function all I see is the assignment of some variables that weren't declared in the function.

I hope this helps and I pray this isn't a troll post....




Last edited on
Topic archived. No new replies allowed.