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
"equilatera l" 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<iostre am>
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+b<c)
cout<<"Cannot form a triangle!";
if (b+c<a)
cout<<"Cannot form a triangle!";
if (a+c<b)
cout<<"Cannot form a triangle!";
}
void angletype()
{int a,b,c;
if(c*c=a*a + b*b)
cout<<"Right";
if(c*c>a*a + b*b)
cout<<"Obtuse";
if(c*c<a*a + b*b)
cout<<"Acute";
}
void sidetype()
{ int a,b,c;
if(a==b==c)
cout<<"Equilate ral Traingle\n";
if(a==b || c==a || b==c)
cout<<"Isoscele s Traingle\n";
else cout<<"Scalene Triangle\n";
}
void main()
{ int a, b, c;
cout<<"Enter the first side:";
cin>>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 "<<a<<" "<<b<<" "<<c<<endl;
} getsides ();
return 0;
} //main
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
"equilatera l" 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<iostre am>
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+b<c)
cout<<"Cannot form a triangle!";
if (b+c<a)
cout<<"Cannot form a triangle!";
if (a+c<b)
cout<<"Cannot form a triangle!";
}
void angletype()
{int a,b,c;
if(c*c=a*a + b*b)
cout<<"Right";
if(c*c>a*a + b*b)
cout<<"Obtuse";
if(c*c<a*a + b*b)
cout<<"Acute";
}
void sidetype()
{ int a,b,c;
if(a==b==c)
cout<<"Equilate ral Traingle\n";
if(a==b || c==a || b==c)
cout<<"Isoscele s Traingle\n";
else cout<<"Scalene Triangle\n";
}
void main()
{ int a, b, c;
cout<<"Enter the first side:";
cin>>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 "<<a<<" "<<b<<" "<<c<<endl;
} getsides ();
return 0;
} //main
Comment