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
|
#include <iostream>
using namespace std;
enum triangles {equilateral, isosceles, scalene, notriangle, triangle};
void getlengths(double & side1, double & side2, double & side3);
triangles determineshape(double side1, double side2, double side3, triangles triangle);
void displayshape(triangles triangle);
int main()
{
char response;
double side1, side2, side3;
do
{
getlengths(side1, side2, side3);
determineshape(side1, side2, side3, triangle);
displayshape(triangle);
cout << "Do you wish to continue (Y or N) : ";
cin >> response;
response = toupper (response);
} while (response == 'Y');
return 0;
}
void getlengths(double & side1, double & side2, double & side3)
{
cout << "input the lengths of side 1" << endl ;
cin >> side1;
cout << "input the lengths of side 2" << endl ;
cin >> side2;
cout << "input the lengths of side 3" << endl ;
cin >> side3;
}
triangles determineshape(double side1, double side2, double side3, triangles triangle)
{
if ((side1 + side2) < (side3))
triangles triangle = notriangle;
else if ((side2 + side3) < (side1))
triangles triangle = notriangle;
else if ((side1 + side3) < (side2))
triangles triangle = notriangle;
else if (side1==side2 && side2 == side3)
triangles triangle = equilateral;
else if (side1==side2 || side1==side3 || side2==side3)
triangles triangle = isosceles;
else
triangles triangle = scalene;
return triangle;
}
void displayshape(triangles triangle)
{
switch(triangle)
{
case notriangle: cout << "not a real triangle"; break;
case equilateral: cout << "this is an equilateral triangle"; break;
case isosceles: cout << "this is an isosceles triangle"; break;
case scalene: cout << "this is a scalene triangle"; break;
}
}
|