Keep Getting A 0 When calculating Volume of Cylinder ?

Jul 20, 2014 at 5:18pm
Code removed lol
Last edited on Jul 21, 2014 at 3:41am
Jul 20, 2014 at 5:37pm
Please explain the constructor (lines 34--41).
Jul 20, 2014 at 6:06pm
+1 To keskiverto. You are initializing them to their uninitialized value which would make them uninitialized still. Maybe you should call the functions you used? or use them outside the class. Also why do your functions return the private variable? That kind of makes your setter a setter and getter. Something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Motorbike.h"

#include <iostream>

int main()
{
    motorbike bike;
    bike.askWheels();
    bike.askBikeType();
    bike.askTankRadius();
    bike.askTankLength();
    std::cout << "tank volume: " << getTankVolue() << std::endl; //fix function so it gets the volume.. or another to set volume 
}


Overall, I would suggest a new layout plan for your class. Also it derives from a vehicle class but I don't see anything from the vehicle class you are using?
Jul 20, 2014 at 6:23pm
no code
Last edited on Jul 21, 2014 at 3:41am
Jul 20, 2014 at 6:40pm
The thing with line 16 though...The constructor is called before that so...When you "initialize" in constructor it doesn't actually do it. Either add this to your getTankVolume TankVolume = 3.14*TankRadius*TankRadius*TankLenght; or make a setTankVolume and through that in there and call that before getting the volume.


Remember constructor is called when an object is created so how is it going to know what the other information is until after it is created.
Last edited on Jul 20, 2014 at 6:41pm
Topic archived. No new replies allowed.