- Your input prototype doesn't match your implementation.
1 2 3 4 5 6 7 8 9 10 11
|
//void input(&double, &double);
// fixed
void input(double&, double&);
void input(double &height, double &radius)
{
cout << "Cone height: ";
cin >> height;
cout << "Cone radius: ";
cin >> radius;
}
|
|
- When calling
input()
you didn't pass any parameters.
- Likewise with your other functions.
-
http://www.cplusplus.com/doc/tutorial/functions/
1 2 3
|
//input();
// fixed
input(height, radius);
|
|
- As TheIdeasMan mentioned above, for every
new
you need to have a
delete
.
1 2 3 4 5 6 7 8
|
//Cone *myCone = new Cone();
// Adhering to the instructions.
Cone *ptr = new Cone();
// . . .
// fixed; end of main()
delete ptr;
|
|
I also need help with the code inside the setup function as I'm not sure how to write that code by passing it by value when its being passed by reference in other functions. How am i supposed to retrieve that info in setup?
|
- When passing parameters by reference like with
input(height, radius)
the passed parameters are aliases for the original variable. So whatever you do in the input function, acts upon the original variable.
- It's best explained with an example.
http://cpp.sh/7d3q
- Because
input(height, radius)
modified your variables of
height
and
radius
in
main()
, you can just pass those as parameters.
- This function is invalid as the return type is void.
- As you are returning the volume, which you declared as a
double
, change the return type of the function to
double
.
- Where are
radius
and
height
declared in this function? Why aren't you using the passed parameter,
ptr
?
- The point of passing parameters is to be able to use them in the function. As
Cone *ptr
is a pointer, you need to use the
->
operator to access the member variables. Example:
http://cpp.sh/4pdy
1 2 3 4 5 6 7 8 9 10 11
|
void getVolume(Cone *ptr)
{
double volume;
// where are radius and height declared?
// btw, you can just do for example, int x = 23 * 34 - 100
// instead of splitting them into 2 lines
volume = (PI * pow(radius, 2) * height)/3.0;
// invalid, as the return type is void
return volume;
}
|
|