holy error messages batman

This is a discussion on holy error messages batman within the C++ Programming forums, part of the General Programming Boards category; well everyone heres the code and I gotta tell yah this one has got me stumped Code: #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    holy error messages batman

    well everyone heres the code and I gotta tell yah this one has got me stumped
    Code:
    #include <iostream> 
    #include <string>     
    
    using namespace std;
    
    
    class two
    {
    private: float x, y;
    public:
    	void read()
    	{
    		cout<<"Enter the x cooridnate: "; cin>>x;       //enter the value for the x coord
    		cout<<"Enter the y coordinate: "; cin>>y;		//enter the value for the y coord
    	}
    
    	void show()
    	{
    	cout<<"the x and y of point a are("<<x<<" , "<<y<<")"<<endl;  //shows the value of the x and y coord
    													
    	}
    
    friend void show(two p)
    	{
    	cout<<"the x and y of point b are("<<p.x<<" , "<<p.y<<")"<<endl;
    	}
    friend float distance(two p)
    	{
    	float d=((0-p.x)(0-p.x)) + (0-p.y)(0-p.y));
    	cout<<sqrt(d);
    	}
    	
    };
    void main()
    {
    	two a, b;//declares two objects a and b
    	a.read();//read in x and y values for object a
    	b.read();//read in x and y values for object b
        a.show();//show x and y values for object a
    	show(b);//show x and y values for object b
    	cout<<"The distance from point(0,0) to point a is" <<distance(b);
    }
    well according to the info I got on friend functions this stuff should work man but I keep getting this crazy error message that says internal compiler error. Now the one question that I have what exactly am I missing here

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    just right off the top of me head.. i can see that you forgot to #include<cmath> whilst using the sqrt() function.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    I have change some statements, now it's ok.

    Code:
    #include <iostream> 
    #include <string>
      
    using namespace std;
    
    class two
    {
    private: float x, y;
    public:
      void read()
      {
        cout<<"Enter the x cooridnate: "; cin>>x;       
        cout<<"Enter the y coordinate: "; cin>>y;  
      }
    
      void show()
      {
      cout<<"the x and y of point a are("<<x<<" , "<<y<<")"<<endl;  
      }
    
    friend void show(two p)
      {
      cout<<"the x and y of point b are("<<p.x<<" , "<<p.y<<")"<<endl;
      }
    friend float distance(two p)
      {
      float d=((0-p.x)*(0-p.x) + (0-p.y)*(0-p.y)); //add * between )(
      return sqrt(d);    //chang cout to return
      }
      
    };
    int main()
    {
      two a, b;    //why define two objects but output one ?               
      a.read();
      b.read();
        a.show();
      show(b);
      cout<<"The distance from point(0,0) to point a is " ;
        cout<<distance(a);  
      
        cin.ignore();  
        cin.get();
      
      return 0;
    }
    Last edited by toysoldier; 09-14-2004 at 03:41 AM.

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Here is something that will actually compile.

    Code:
    #include<iostream> 
    #include<string>
    #include<cmath>
      
    using namespace std;
    
    class two
    {
    private: float x, y;
    public:
      void read()
      {
        cout<<"Enter the x cooridnate: "; cin>>x;       
        cout<<"Enter the y coordinate: "; cin>>y;  
      }
    
    void show()
      {
      cout<<"the x and y of point a are("<<x<<" , "<<y<<")"<<endl;  
      }
    
    void show(two p)
      {
      cout<<"the x and y of point b are("<<p.x<<" , "<<p.y<<")"<<endl;
      }
    float distance(two p)
      {
      float d=((0-p.x)*(0-p.x) + (0-p.y)*(0-p.y)); //add * between )(
      return sqrt(d);    //chang cout to return
      }
      
    };
    int main()
    {
      two a, b;    //why define two objects but output one ?               
      a.read();
      b.read();
       a.show();
       b.show(b);
      cout<<"The distance from point(0,0) to point a is " ;
        cout<<a.distance(a);  
      
        cin.ignore();  
        cin.get();
      
      return 0;
    }
    Last edited by The Brain; 09-14-2004 at 04:26 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    #include<cmath>
    why not include this statement, but result is correct?
    so I remove this statement.

  6. #6
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    my bad.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. holy keyboard batman!
    By Glirk Dient in forum Tech Board
    Replies: 4
    Last Post: 07-17-2005, 05:22 PM
  2. Holy crap
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 12-08-2004, 10:14 AM
  3. the holy grail for newbie programmers...
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 10-08-2003, 07:19 PM
  4. Holy Shiznit
    By Cshot in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-14-2002, 09:52 AM
  5. riddle me this, batman
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-25-2002, 04:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21