Thread: Help with structs...

  1. #1
    Registered User
    Join Date
    Nov 2011

    Help with structs...

    Hi, I have to do an assignment(explained in code) and I keep getting this error:
    PHP Code:
    In function 'int main()':
    errorconversion from 'Point' to non-scalar type 'MathVector' requested 
    (The little red x is at the last line in main)
    Can someone please tell me what I need to change in order to make this program work. Thank you.

    // This program reads and stores start and end coordinates of two vectors// and then determines if the vectors are orthogonal or not using the
    // dot product equation
    // including required libraries
    #include <iostream>
    #include <cmath>
    // using namespace
    using namespace std;
    // struct definitions & declarations
    struct Point
        double x;
        double y;
        double z;
    struct MathVector
    Point start;
    Point end;
    // Function prototypes
    Point ReadPoint();
    double DistanceBetweenPoints( const Point& pt1, const Point& pt2 );
    void Dot_Product ( MathVector sa,  MathVector ea,  MathVector sb, MathVector eb);
    // main function
    int main()
        Point starta = ReadPoint();
        Point enda = ReadPoint();
        Point startb = ReadPoint();
        Point endb = ReadPoint();
        Dot_Product (starta, enda, startb, endb);
    // function definition
    Point ReadPoint()
        double x1;
        double y1;
        double z1;
    cout << "Enter the coordinates x, y, and z of the point: ";
    cin >> x1 >> y1 >> z1;
    Point pt1;
    return pt1;
    double DistanceBetweenPoints( const Point& pt1, const Point& pt2 )
        double x1= pt1.x;
        double x2= pt2.x;
        double y1= pt1.y;
        double y2= pt2.y;
        double z1= pt1.z;
        double z2= pt2.y;
    double distance = sqrt(pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2));
    return distance;
    void Dot_Product ( MathVector sa,  MathVector ea,  MathVector sb, MathVector eb)
        double x_starta = sa.start.x;
        double x_enda = ea.end.x;
        double x_startb = sb.start.x;
        double x_endb = eb.end.x;
        double y_starta = sa.start.y;
        double y_enda = ea.end.y;
        double y_startb = sb.start.y;
        double y_endb = eb.end.y;
        double z_starta = sa.start.z;
        double z_enda = ea.end.z;
        double z_startb = sb.start.z;
        double z_endb = eb.end.z;
        double product = (x_enda-x_starta)*(x_endb-x_startb)+ (y_enda-y_starta)*(y_endb-y_startb)+(z_enda-z_starta)*(z_endb-z_startb);
        if (product == 0)
            cout << "The vectors are orthogonal.";
            cout << "The vectors are not orthogonal.";

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    You declared your dot product function to take 4 vectors but then pass in 4 points. That's the syntactical error. From a mathematical point of view I don't understand your code. A mathematical vector is nothing but a point with a different definition. (4/2/17) is a vector. A vector is not defined by two points because that would limit it to exactly one start and one end. A dot product takes two vectors. Not 4.
    Last edited by nvoigt; 11-25-2011 at 01:51 AM. Reason: 2D -> 3D vector

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    You know, it probably doesn't matter a lot but, a vector *isn't* a line segment!

    What you've tried to build is a line segment, with a start and an end. A mathematical vector has only direction and magnitude, not position, thus the possible ways to represent it is by either a n-sized column holding the "cartesian" coordinates of the origin added with it, or a (n-1)-sized column holding its "polar" coordinates and nth element for lenght.

    ( Just to keep heads spinning... )
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [ noob question ] Help with structs within structs
    By Riverfoot in forum C Programming
    Replies: 3
    Last Post: 04-26-2011, 08:24 PM
  2. Passing Structs Into An Array Of Structs.
    By TheTaoOfBill in forum C Programming
    Replies: 3
    Last Post: 10-07-2010, 10:38 AM
  3. Replies: 3
    Last Post: 03-31-2009, 01:34 PM
  4. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM
  5. structs
    By Care4246 in forum C Programming
    Replies: 3
    Last Post: 10-02-2003, 12:25 AM

Tags for this Thread

Website Security Test