Triangular c++ edge calculation -


i have been working on source code, nothing seems go right. revised source code extremely appreciated, or @ least visual solution errors.

here following problem: write program reads 3 edges triangle , determines whether input valid. input valid if sum of 2 edges greater third edge. here sample runs of program: enter 3 edges 1, 2.5, 1 [enter] can edges 1, 2.5, , 1 form triangle? false

here have far source code":

#include <iostream> using namespace std;  bool valid (int tri_a, int tri_b, int tri_c); bool triangle;    int main () { int a; int b; int c; cout << "enter 3 edges: "; double edge1, edge2, edge3; cin >> edge1 >> edge2 >> edge3;  bool isvalid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge3 + edge2 > edge1); cout << " enter 1st value: "; cin >> a; cout << " enter 2nd value: "; cin >> b; cout << " enter 3rd value: ";  cin >> c;      bool triangle = valid (a, b, c);  { if (triangle == true) cout << "valid" << endl; else cout << "invalid" << endl;  }   system ("pause");  return 0;  } 

edit: answers , comments here beginning sound crazy. said, in triangle, sum of every 2 edges must bigger third! 1+1>sqrt(2), 1+sqrt(2)>1, sqrt(2)+1>1 example 90 degree triangle 2 1 length edges. logic of isvalid fine.

here's quote wikipedia article:

he sum of lengths of 2 sides of triangle exceeds length of third side, principle known triangle inequality. since vertices of triangle assumed non-collinear, not possible sum of length of 2 sides equal length of third side.


well, didn't define valid method. also, why reading 3 values , 3 values one-by-one??

here's quick fix, see if works (haven't tested it):

#include <iostream> using namespace std;   int main () {     cout << "enter 3 edges: ";     double edge1, edge2, edge3;     cin >> edge1 >> edge2 >> edge3;      bool isvalid = (edge1 + edge2 > edge3) &&     (edge1 + edge3 > edge2) && (edge3 + edge2 > edge1);      if (isvalid)         cout << "valid" << endl;     else         cout << "invalid" << endl;        system ("pause"); //not sure if right, left here.     return 0; } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -