473,406 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Totally lost help Triangle program

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<iostream>
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<<"Equilateral Traingle\n";
if(a==b || c==a || b==c)
cout<<"Isosceles 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
Oct 25 '06 #1
5 6575
vermarajeev
180 100+
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
  1. void getsides(int& a, int& b, int& c)
  2. {    
  3.     cout<<"Enter side a: ";
  4.     cin>>a;
  5.     cout<<"Enter side b: ";
  6.     cin>>b;
  7.     cout<<"Enter side c: ";
  8.     cin>>c;
  9. }
  10.  
  11. void swap (int& a , int& b) 
  12.     int temp;
  13.     temp = a; 
  14.     a = b; 
  15.     b = temp; 
  16.  
  17. void triangle (int a, int b, int c)
  18. {
  19.     if(a+b<c)
  20.       cout<<"Cannot form a triangle!";
  21.     if(b+c<a)
  22.      cout<<"Cannot form a triangle!";
  23.     if(a+c<b)
  24.      cout<<"Cannot form a triangle!";
  25. }
  26.  
  27. void angletype(int a, int b, int c)
  28. {    
  29.     if((c*c) == ((a*a) + (b*b)))
  30.           cout<<"Right";
  31.     if((c*c) > ((a*a) + (b*b)))
  32.           cout<<"Obtuse";
  33.     if((c*c) < ((a*a) + (b*b)))
  34.           cout<<"Acute";
  35. }
  36.  
  37. void sidetype(int a, int b, int c)
  38. {    
  39.      if(a==b==c)
  40.            cout<<"Equilateral Traingle\n";
  41.      if(a==b || c==a || b==c)
  42.            cout<<"Isosceles Traingle\n";
  43.      else 
  44.            cout<<"Scalene Triangle\n";
  45. }
  46.  
  47. void sortsides(int& a, int& b, int& c)
  48. {
  49.      if (a>b) 
  50.     swap(a, b); 
  51.     if (b>c) 
  52.                 swap(b, c); 
  53.     if (a>b) 
  54.     swap(a, b);         
  55. }
  56.  
  57. int main() 
  58.        int a, b, c;
  59.        getsides(a, b, c);
  60.        while(1)
  61.        {
  62.     if(a==0 && b==0 && c==0)
  63.      break;
  64.     sortsides(a, b, c);
  65.     cout<<a<<b<<c<<endl;
  66.     getsides(a, b, c);
  67.       }    
  68. return 0;
  69. }
Thankx
Oct 25 '06 #2
singhm
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<iostream>
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<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,int b,int c)
{
if((c*c)==((a*a) + (b*b)))
cout<<"Right Triangle \n";
if((c*c)>((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 "<<a<<" "<<b<<" "<<c<<endl;
break;
}
sortsides (a,b,c);
swap (a,b);
triangle(a,b,c);
{sidetype(a,b,c);
angletype(a,b,c);
}
getsides(a,b,c);
}
return 0;
}


thanks
Oct 25 '06 #3
Banfa
9,065 Expert Mod 8TB
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
vermarajeev
180 100+
Try out something like this

Expand|Select|Wrap|Line Numbers
  1. bool triangle (int a, int b, int c)
  2. {
  3.     if( (a+b<c) || (b+c<a) ||  (a+c<b) )
  4.      {
  5.            return false;
  6.      }
  7.    return true;
  8. }
Then in main you can test like this

Expand|Select|Wrap|Line Numbers
  1. if( triangle(a,b,c) )
  2.    cout<<"This forms a triangle"<<endl;
  3. else
  4.    cout<<"Cannot form a triangle"<<endl;
Thankx
Oct 26 '06 #5
singhm
5
No thank you!
Oct 26 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: coinjo | last post by:
I need to write a program, which takes two inputs: •a value n that represents the number of elementsin the longest row of a triangle. •a character c to be printed in place of each...
9
by: coinjo | last post by:
I need to write a program, which takes two inputs: •a value n that represents the number of elementsin the longest row of a triangle. •a character c to be printed in place of each...
16
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hi, Could anyone over here, write a program in C using only for loop to print the following output * *** ***** ******* ********* ***********
25
by: GUPTAJI | last post by:
hi all, can u give me the code to create a Pascal's Triangle........... and yes, it should work thankx
12
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
0
geo039
by: geo039 | last post by:
I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 constructors...
4
by: Aaron | last post by:
Hi, I have written a pascals triangle program. However, my program gets a floating point exception somewhere between 60 and 70 and any subsequent larger value. This is no doubt due to dividing...
11
by: inferi9 | last post by:
hi everyone I am new here and I have this C++ program that I have to write but it keep given me nothing useful. here is the question: A right triangle can have sides that are all integers. A...
6
by: jackj | last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.