Hi, I have to do an assignment(explained in code) and I keep getting this error:
PHP Code:
In function 'int main()':
error: conversion 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.
Code:
// 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;
pt1.x=x1;
pt1.y=y1;
pt1.z=z1;
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.";
else
cout << "The vectors are not orthogonal.";
return;
}