Do while problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Do while problem

chess2009chess2009 Posts: 4Member
Could you please help why my program goes through do while loop just once, although the condition is true.
//Program is getting numbers from user and realize whether they are correct numbers for triangle side or not and if tey find out the area//


#include
#include
double TraingleArea();
int main(void)
{
int Firstside,Secondside,Thirdside;
char Answer;
do
{
printf("Enter your Triangle's side
");
scanf("%d %d %d", &Firstside, &Secondside, &Thirdside);
if(Firstside<=0 || Secondside<=0 || Thirdside<=0)
printf("Sides of traingle are positive,please enter three positive integer numbers.");
else
{
if(Firstside+Secondside<=Thirdside || Secondside+Thirdside<=Firstside ||Firstside+Thirdside<=Secondside)
printf("They are not valid numbers for sides of traingle.");
else
{
if(Firstside==Secondside && Secondside==Thirdside)

printf("The tringle is Equilateral Its area is equal to %f
",TraingleArea(Firstside,Secondside,Thirdside) );

else if(Firstside==Secondside || Firstside==Thirdside || Secondside==Thirdside)

printf("The triangle is Isosceles Its area is equal to %f
",TraingleArea(Firstside,Secondside,Thirdside) );

else
printf("The triangle is Scalene Its area is equal to %f
",TraingleArea(Firstside,Secondside,Thirdside) );
}

}
printf("Would you like to continue? Y/N
");
scanf("%c",&Answer);
}while(Answer=='Y');

}

double TraingleArea(unsigned Firstside,unsigned Secondside, unsigned Thirdside)
{
double halfPerimeter=(double)(Firstside+Secondside+Thirds ide)/2;
double Area;
Area=sqrt(halfPerimeter*(halfPerimeter-Firstside)*(halfPerimeter-Secondside)*(halfPerimeter-Thirdside));
return Area;
}

Comments

Sign In or Register to comment.