Triangle Angle Project
Nov 22, 2015 at 6:53pm UTC
Hey everyone,
I'm pretty much finished this project except I keep running into one issue. The bool function seems to only work once. For example, if I input 3, 4, and 9 it will tell me 3, 4, and 9 does not form a triangle which is true. However if I try to enter 3, 4, and 9 after that first time, it will compute it anyway though it does not form a triangle. I'm not sure what I'm doing wrong.
Thanks!
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int sides = 3;
double side[sides];
string r1, r2;
void getSides()
{
cout << "Entering 0 for all 3 sides will end the program." << endl;
cout << "Enter side A: " ;
cin >> side[0];
cout << "Enter side B: " ;
cin >> side[1];
cout << "Enter side C: " ;
cin >> side[2];
}
void sortSides()
{
if (side[1] < side[0])
{
swap(side[1], side[0]);
}
if (side[2] < side[0])
{
swap(side[2], side[0]);
}
if (side[2] < side[1])
{
swap(side[2], side[1]);
}
}
void display1()
{
if (side[0] == side[1] && side[0] == side[2])
{
cout << "equilateral " ;
}
else if (side[0] == side[1] || side[0] == side[2] || side[1] == side[2])
{
cout << "isosceles " ;
}
else
{
cout << "scalene " ;
}
}
void display2()
{
double c1 = (side[2] * side[2]), a1 = (side[0] * side[0]), b1 = (side[1] * side[1]);
if (c1 == a1 + b1)
{
cout << "right " ;
}
if (c1 > a1 + b1)
{
cout << "obtuse " ;
}
if (c1 < a1 + b1)
{
cout << "acute " ;
}
}
bool formTriangle()
{
if (side[0] < side[1] + side[2])
return true ;
else
return false ;
}
int main()
{
do
{
if (formTriangle() == 1)
{
getSides();
sortSides();
cout << "The sides " << side[0] << ", " << side[1] << ", and " << side[2] << " form a " ;
display1();
display2();
cout << "triangle." << endl;
}
if (formTriangle() == 0)
{
getSides();
sortSides();
cout << "The sides " << side[0] << ", " << side[1] << ", and " << side[2] << " does not form a triangle." << endl;
}
} while (side[0] != 0 && side[1] != 0 && side[2] != 0);
system("PAUSE" );
return 0;
}
Topic archived. No new replies allowed.