448,652 Members | 1,694 Online Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

# Totally lost help Triangle program

 P: 5 Hi guys so I have a trianlge program having hard time finishing this though, I have to develop a program which is the following: Write a program that will allow the user to enter the 3 lengths and then tell what kind of triangle the 3 lengths form. Function main should consist mainly of a loop and calls to functions. Let the functions do the work. (Think of main as the boss who delegates all of the work to others.) main: loops until 0,0,0 is entered as the sides. For each set of sides: * Sort the 3 sides A, B, and C such that A<=B<=C If you sort them first everything else gets easier! * If they do form a triangle print the side type and the angle type. * If they do not form a triangle, print an appropriate message. The lengths are supposed to be the sides of a triangle, but it is possible to enter 3 lengths that do not form a triangle: for example 3, 5, and 12. (Why can't you make a triangle with those sides? Think in terms of if statements. A function sortSides that will assign the lengths of the sides to A, B, and C such that A<=B<=C A function swap that will swap 2 values - called by sortSides A function sideType that will print "equilateral" if the lengths of all 3 sides are equal "isosceles" if any two sides (but not all 3) are equal "scalene" if no sides are equal A function angleType that will print "right" if C*C = A*A + B*B "obtuse" if C*C > A*A + B*B "acute" if C*C < A*A + B*B THIS IS WHAT I GOT ANY SUGGESTIONS WOULD BE GREATLY APPRECIATED SO I DONT FAIL. THANKS #include using namespace std; void getsides() {int a,b,c; cout<<"Enter side a: "; cin>>a; cout<<"Enter side b: "; cin>>b; cout<<"Enter side c: "; cin>>c; } void swap (int& a , int& b); { int temp; temp = a; a = b; b = temp; } void triangle (int a, int b, intc); { if(a+ba*a + b*b) cout<<"Obtuse"; if(c*c>a; cout<<"Enter the second side:"; cin>>b; cout<<"Enter the third side:"; cin>>c; if (a>b) swap(a, b); if (b>c) swap(b, c); if (a>b) swap(a, b); while(getsides(a,b,c,);!=0,0,0) {sortsides (a,b,c): trainlge(a,b,c); {sidetype(a,b,c); angletype(a,b,c); } else cout<<"Not a traingle "<
5 Replies

 100+ P: 180 This is not the complete program, I have solved almost 80%, remaining try to do by yourself...If I give you the entire answer you will not learn anything...So try out after this Expand|Select|Wrap|Line Numbers void getsides(int& a, int& b, int& c) {         cout<<"Enter side a: ";     cin>>a;     cout<<"Enter side b: ";     cin>>b;     cout<<"Enter side c: ";     cin>>c; }   void swap (int& a , int& b)  {      int temp;     temp = a;      a = b;      b = temp;  }    void triangle (int a, int b, int c) {     if(a+b ((a*a) + (b*b)))           cout<<"Obtuse";     if((c*c) < ((a*a) + (b*b)))           cout<<"Acute"; }   void sidetype(int a, int b, int c) {          if(a==b==c)            cout<<"Equilateral Traingle\n";      if(a==b || c==a || b==c)            cout<<"Isosceles Traingle\n";      else             cout<<"Scalene Triangle\n"; }   void sortsides(int& a, int& b, int& c) {      if (a>b)      swap(a, b);      if (b>c)                  swap(b, c);      if (a>b)      swap(a, b);          }   int main()  {         int a, b, c;        getsides(a, b, c);        while(1)        {     if(a==0 && b==0 && c==0)      break;     sortsides(a, b, c);     cout<

 P: 5 Hey- Can you help me out on this? Everything wokrs for me now I jsut need the program to end after the user enters in sides such as; 1-1-4 it outputs cannot form a triangle which is correct but it goes on to say side type & angle type functions, i need it to stop after cannot form a triangle the simplest way , any thoughts ?? #include using namespace std; void sidetype(int a, int b, int c) { if(a==b && a==c && b==c) cout<<"Equilateral Traingle\n"; else if(a==b || c==a || b==c) cout<<"Isosceles Traingle\n"; else cout<<"Scalene Triangle\n"; } void sortsides(int&a, int&b, int&c) { if (a>b) swap(a, b); if (b>c) swap(b, c); if (a>b) swap(a, b); } void getsides(int&a, int&b, int&c) { cout<<"Enter side a: "; cin>>a; cout<<"Enter side b: "; cin>>b; cout<<"Enter side c: "; cin>>c; } void swap (int&a, int&b) { int temp; temp=a; a=b; b=temp; } void triangle (int a, int b, int c) { if(a+b((a*a) + (b*b))) cout<<"Obtuse Triangle \n"; if((c*c)<((a*a) + (b*b))) cout<<"Acute Triangle \n"; } int main() { int a, b, c; getsides(a,b,c); while(1) { if(a==0 && b==0 && c==0){ cout<<"Not a triangle "<

 Expert Mod 5K+ P: 8,916 perhaps you should return a value from the function triangle(...) indicating if it actually is or isn't a triangle and then only call the other functions if it is a triangle. Oct 26 '06 #4

 100+ P: 180 Try out something like this Expand|Select|Wrap|Line Numbers bool triangle (int a, int b, int c) {     if( (a+b

 P: 5 No thank you! Oct 26 '06 #6 