0
#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. :)

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by MrsHeard
0

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

0

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

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

Is something missing?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.