Function Help
Sep 13, 2016 at 9:34pm UTC
I am trying to create a function that gets the area of a triangle with the user inputting the points (input is in another function). However, I cannot seem to get this to work, I keep getting an error along the lines of "Cannot use expression as function." I have tried googling a solution and have found none.
Here is the function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<#include "Triangle .h"
#include <cmath>
Triangle ::setPoints (int p1x, int p1y, int p2x, int p2y, int p3x, int p3y)
{
p1x=p1x;
p1y=p1y;
p2x=p2x;
p2y=p2y;
p3x=p3x;
p3y=p3y;
}
Triangle::Triangle(double )
{
double area;
area = (p1x(p2y-p3y)+p2x(p3y-p1y)+p3x(p1y-p2y))/2;
}/>
Here is the header File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//Function Declarations
#ifndef TRIANGLE _H
#define TRIANGLE _H
#include <iostream>
#include <cmath>
using namespace std;
class Triangle
{
//Member Variables
public :
Triangle (const );
setPoints (const );
getArea (const );
getCenterPoint (const );
virtual ~Triangle ();
//Overload Constructor
setPoints(int ,int ,int , int , int , int );
getArea (double );
Triangle(double );
//Private
private :
int p1x, p1y, p2x, p2y, p3x, p3y;
};
#endif // TRIANGLE _H
Thanks for any help!
Sep 13, 2016 at 9:39pm UTC
p1x(p2y-p3y)
is mathematical notation.
C++ requires explicit operators for everything:
p1x*(p2y-p3y)
Sep 13, 2016 at 9:50pm UTC
Thanks So much! I can't believe I forgot that.
Topic archived. No new replies allowed.