c++ HELP!!!!

help!!!!!!!!!!!!!! i need to calculate the area of a triangle using heron's formula.
i wrote the code below and i need to modify it so that a user is required to keep entering the three side until he/she decides to stop. If the three sides entered make an invalid triangle, the user is required to re-enter the values until valid triangle is formed. Then the area is displayed.

#include <iostream>
#include <cmath>
using namespace std;

int main(){
double a,b,c=0;
double s,A=0;

cin>>a>>b>>c;
cout<<"Enter three sides: "<<a<<" "<<b<<" "<<c<<endl;
while(!(a<=0||b<=0||c<=0||((a+

b)<=0)||((a+c)<=0)||((b+c)<=0))){

if((a>0)&&(b>0)&&(c>0)&&((a+b)>c)&&((a+c)>b)&&((b+c)>a)){
s=(a+b+c)/2;
A=sqrt(s*(s-a)*(s-b)*(s-c));

cout<<A;
}
else{
cout<<"Enter three sides: "<<a<<" "<<b<<" "<<c<<endl;
}

}
return 0;
}

the screen output should like this:

Enter three sides of a triangle: 0 1 2 Error!

Re-enter three sides of a triangle: -1 1 2 Error!

Re-enter three sides of a triangle: 3 4 5 => 6

Continue (y/n)? y

Enter three sides of a triangle: 1 1 2 Error!

Re-enter three sides of a triangle: 6 8 10 => 24

Continue (y/n)? n

Done!

Please note that Continue (y/n)? only displayed after a valid triangle is formed. Otherwise, the user needs to re-enter sides until it's valid.

pleeeeeeeeeeeeeeeaaaaaaaaaaaaase help me with this. the assignment is due in a few hours and i need to get it done.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// triangle area by herons formula
#include <iostream>
#include <cmath>
using namespace std;

int main(){
	
	double a,b,c,s, Area=0;
	char ch;
	tryAgain:
	cout << "Enter the length of 3 sides: \n";
	cin >>a >>b >>c;
	
	if (a<0 || b<0 || c<0 || a>(b+c) || b>(c+a) || c>(a+b) )
	{
		cout << "invalid input. try again.\n";
		goto tryAgain;
	}
		


	s=(a+b+c)/2;
	
	Area = sqrt( s*(s-a)*(s-b)*(s-c) );
	cout << "Area = " << Area << endl;

	cout << "enter y to continue. other to stop\n";
	cin >> ch;
	
	if (ch=='y')
	{
		cout << "New triangle:\n";
		goto tryAgain;
	}
	
	else 
		return 0;
}
Topic archived. No new replies allowed.