Write a program that will prompt the user to input and integer that denotes sizes of sides of a triangle and determine the following:
a. determine if it forms a triangle or not;
b. if it forms a triangle, determine if it is and isosceles, equilateral or scalene.
c. if it doesn't form a triangle, then program should prompt the user that the inputs don't form a triangle.
Note: Consider the following guidelines:
a. isosceles triangle is described by having 2 sides equal.
b. equilateral triangle is described by having all 3 sides equal.
c. scalene triangle is described by having no sides equal.
d. to determine if the triangle really forms a triangle, the sum of 2 sides must be greater than the other side.
e. please provide comments of your program.
Please help me ,
do your own homework
(or pay me)
Please Help me. I beg you.
>>18045452
I accept Bitcoin or Paypal
>>18045421
Google is invented .. you know this, right ?
http://codereview.stackexchange.com/questions/18463/determining-triangle-type-from-three-integer-inputs
Remember to personalize it or get caught.
-> stackoverflow triangle shit in java
Else, I suppose you have learned the basics, it is simply some if tests and printing
If it has 3 coordinates it is a triangle
If 3 segments (point b - point a is ab segment) are the same size..
Else if 2 segments have the same size.. Etc
In how many hours time do you need it?
[code]
//Here is a functional C version of what you need. Have fun porting it to Java :D
//Will span two posts, (too long).
//This example is freeware.
#include <stdio.h>
//Internal variables for Triangle class need to be somewhat like this.
struct triangle
{
int sides[3];
int isIsosceles;
int isEquilateral;
int isScalene;
int isTriangle;
};
//For internal usage only. Should be a class function.
int setTriangle(struct triangle *tri)
{
if( tri->sides[0] + tri->sides[1] == tri->sides[2] )
{
tri->isTriangle = 0;
return 0;
}
if( tri->sides[0] + tri->sides[2] == tri->sides[1] )
{
tri->isTriangle = 0;
return 0;
}
if( tri->sides[1] + tri->sides[2] == tri->sides[0] )
{
tri->isTriangle = 0;
return 0;
}
tri->isTriangle = 1;
return 0;
}
//For internal usage only. Should be a Class function.
int setIsosceles(struct triangle *tri)
{
int sameside=0;
if( tri->sides[0] == tri->sides[1] )
sameside++;
if( tri->sides[0] == tri->sides[2] )
sameside++;
if( tri->sides[1] == tri->sides[2] )
sameside++;
if( sameside == 1 && tri->isTriangle == 1 )
tri->isIsosceles = 1;
else
tri->isIsosceles = 0;
return 0;
}
[/code]
[code]
//For internal usage only. Should be a Class function.
int setEquilateral(struct triangle *tri)
{
[/code]
if( ( tri->sides[0] == tri->sides[1] ) &&
( tri->sides[0] == tri->sides[2] ) )
{
tri->isEquilateral = 1;
return 0;
}
tri->isEquilateral = 0;
return 0;
}
//For internal usage only. Should be a Class function.
int setScalene(struct triangle *tri)
{
if( tri->sides[0] != tri->sides[1] &&
tri->sides[0] != tri->sides[2] &&
tri->sides[1] != tri->sides[2] )
{
tri->isScalene = 1;
return 0;
}
tri->isScalene = 0;
return 0;
}
//Run this when you have set the values for tri->sides[]
//This is how and what the Constructor should do.
int setupTriangle(struct triangle *tri)
{
setTriangle(tri); //Has to be done first.
setIsosceles(tri);
setEquilateral(tri);
setScalene(tri);
}
int main(void)
{
struct triangle tri;
int a;
//You may want to make a constructor that acceps the measurements of sides as variables.
for( a=0; a<3; a++ )
{
printf("Enter length of side %d of triangle: ", a);
scanf("%d", &tri.sides[a]);
}
setupTriangle(&tri);
printf("is triangle?\t %s\n", tri.isTriangle? "yes":"no");
printf("is isosceles?\t %s\n", tri.isIsosceles? "yes":"no");
printf("is equilateral?\t %s\n", tri.isEquilateral? "yes":"no");
printf("is scalene?\t %s\n", tri.isScalene? "yes":"no");
return 0;
}
exactly how do you preserve whitespace here?