Advertisement

Garbage Values Appearing in Console?

Started by June 10, 2002 09:32 PM
1 comment, last by Kevinator 22 years, 5 months ago
I''m having some trouble with garbage values appearing when I run a program I created. (It is actually my first (very simple) class!)
  #pragma hdrstop

#include <condefs.h>
#include <iostream.h>
#include <conio.h>

#pragma argsused

class point
{
        public:
                point(float,float,float);
                ~point();
                void change(float,float,float);
                display();

        private:
                float posx,
                      posy,
                      posz;
};

point::point(float x, float y, float z)
{
        posx = x;
        posy = y;
        posz = z;
}

point::~point()
{

}

void point::change(float x, float y, float z)
{
        posx = x;
        posy = y;
        posz = z;
}

point::display()
{
        cout << "X: " << posx << endl;
        cout << "Y: " << posy << endl;
        cout << "Z: " << posz << endl;
}

int main()
{
        point point_1(1.0,1.0,1.0);
        cout << point_1.display();   //displays coords of point_1

        point_1.change(1.5,2.6,24.56);  //changes coords of point_1

        cout << point_1.display();    //display new coords

        getch();
}  
And when I run it, this is the output:
X: 1
Y: 1
Z: 1
4335472X: 1.5
Y: 2.6
Z: 24.56
4335472 
This value is somewhat random everytime I change my program. I''m sorry, I normally wouldn''t ask something like this here, but I''ve debugged and strained my brain for long enough! Thanks!
cout << point_1.display();

Guess what this line is doing
(Hint: try removing the ''cout <<'' part, and then running your program again).
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
/me slaps forehead

LMAO! I just wasted an hour of my life on the stupidest thing ever.

Thanks.

This topic is closed to new replies.

Advertisement