Keep Getting A 0 When calculating Volume of Cylinder ?

Code removed lol
Last edited on
Please explain the constructor (lines 34--41).
+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?
no code
Last edited on
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
Topic archived. No new replies allowed.