#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int triangleType(double x1, double y1, double x2, double y2, double x3, double y3);
double distance(double a1, double b1, double a2, double b2);

int main()
{
double x1, y1, x2, y2, x3, y3;

cout << "Enter vertices for the triangle." << endl;
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
cin >> x3;
cin >> y3;

cout << "The function will return 3 for an equilateral triange, 2 for an isosceles triangle and 0 for a scalene triangle" << endl;
cout << "The triangle is type ";
triangleType(x1, y1, x2, y2, x3, y3);
cout << "." << endl;

cout << endl;
system("pause");
return 0;
}

int triangleType(double x1, double y1, double x2, double y2, double x3, double y3)
{
double side1, side2, side3;

side1 = distance(x1, y1, x2, y2);
side2 = distance(x2, y2, x3, y3);
side3 = distance(x3, y3, x1, y1);

if(side1==side2 && side2==side3)
{
return 3;
}

else if(side1==side2 || side2==side3 || side1=side3) // code error here
{
return 2;
}

else
{
return 0;
}
}

double distance(double a1, double b1, double a2, double b2)
{
double dist;
dist = sqrt(pow((a2-a1), 2) + pow((b2-b1), 2));
return dist;
}

Even though this wont compile at the moment I don't think the code is working, there must be a flaw in my logic or calculations somewhere.

The object of this code is to take 3 vertices and return whether the triangle is isosceles, equilateral or scalene.
It just wont return a value for me!
All help much appreciated. :)

Look at the last part of your long "if" statement:

else if(side1==side2 || side2==side3 || side1=side3) // code error here

Is something missing?

All 3 Replies

Oh also I'm new to functions, completely missed it in computers class so this may be totally wrong

Look at the last part of your long "if" statement:

else if(side1==side2 || side2==side3 || side1=side3) // code error here

Is something missing?

Ah, my bad silly mistake then.
Thanks so much for pointing that out!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.