getting strange print out for calculation of volume

// DEBUG3-4
// This program contains a class for a cylinder
// Data members are radius and height
// The volume is calculated as pi times radius squared times height
// If no height is given, it's not a cylinder - it's a circle!

#include<iostream>
using namespace std;
//declaration section


class Cylinder
{
private:
double radius;
double height;
static double pi;
double volume;
public:
Cylinder(const double r);
Cylinder(const double r, const double h);
void showData(void);
double convert(void);
};


double Cylinder::pi=3.1459;

// implementation section
Cylinder::Cylinder(const double r)
{
Cylinder::radius=r;

cout<<"This is a circle - It has no volume!!"<<endl;
Cylinder::volume = convert();
}

Cylinder::Cylinder(const double r, const double h)
{
Cylinder::radius = r;
Cylinder::height = h;
Cylinder::volume = h* r;
}

double Cylinder::convert(void)
{
double vol;
volume = pi * (Cylinder::radius * Cylinder::radius) * Cylinder::height;
return(volume);
}


void Cylinder::showData(void)
{
cout<<"Cylinder is "<<Cylinder::radius<<" by "<<Cylinder::height;
cout<<" Volume is "<<Cylinder::volume<<" "<<endl<<endl;
}


int main()
{
Cylinder oneCylinder(3,5);
oneCylinder.showData();
Cylinder oneCircle(8);
oneCircle.showData();
system("pause");
}
┬┐what's strange?
Topic archived. No new replies allowed.