samedi 31 janvier 2015

How do I use relationships btwn 3 integers to determine a triangle and/or what declaration can I use to make this program work?

I am trying to create a program that can use relationships to determine the type of triangle being calculated. I have tried float and double declarations but either way the end result is incorrect and is draving me crazy. Basically the program does not regognize "c" as being equal to a/b for every like value.(Ex. enter 7 7 for sides a and b, and 60 for angle, should yield an equilateral, but does not.) Any ideas as to how I might address this? Thank you so much!



#include <iostream>
#include <cmath>
#define pi 3.14159265358989

using namespace std;

int main()
{
float a, b, c, d, C;


cout << "Hello. I can calculate the missing length of a triangle" << endl;
cout << "by using using the information you provide." << endl;
cout << "Please enter two positive integers between 1-99 and separate them with a space. " << endl;
cin >> a >> b;
cout << "Side 1 equals: " << a << endl;
cout << "Side 2 equals: " << b << endl;
cout << "Please enter the angle between the two sides you just entered. " << endl;
cin >> d;

C = d * (pi / 180); // convert rad to deg
//Compute missing side
c = sqrt((a*a) + (b*b) - 2 * a * b * cos(C));
cout << "The length of the third side of the triangle is: " << c << endl;

if (a == b && b == c) //all sides are equal
cout << "This is an Equilateral Triangle." << endl;

else if (a == b && b != c) // if 2 sides are equal

cout << "This is an Isosceles Triangle. " << endl;

else if (a != b && b != c) // if no sides are equal

cout << "This is a Scalene Triangle. " << endl;


system ("pause");
return 0;


}


Aucun commentaire:

Enregistrer un commentaire