- #1
ineedhelpnow
- 651
- 0
compute the area of a triangle. write an if/else statement to check if the three sides provide a valid triangle. to make a valid triangle, all sides have to be positive and the sum of any two sides must be greater than the third. add a while loop so that if the sides are invalid the user is asked to re enter the sides.
this is what i wrote. is it correct? i compiled it on this site Compile and Execute C++ online i don't know if you can see my code if not you can just copy and paste it there. at the bottom of the page it says STDIN Input. you can enter sides to test it. just leave a space between them (i.e. 3 8 -2). this question will be brought on our midterm so i want to make sure i did it absolutely correct now and that no errors slip past me.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double a=0,b=0,c=0;
cin >>a>>b>>c;
double A=0;
double s=0;
s=(a+b+c)/2;
A=sqrt(s*(s-a)*(s-b)*(s-c));
if(((a>0)&&(b>0)&&(c>0))&&(((a+b)>c)&&((a+c)>b)&&((b+c)>a))) {
while(!(a<=0||b<=0||c<=0||(a+b)<=0||(a+c)<=0||(b+c)<=0))
cout << A;
}
else
cout << "Error.";
}
this is what i wrote. is it correct? i compiled it on this site Compile and Execute C++ online i don't know if you can see my code if not you can just copy and paste it there. at the bottom of the page it says STDIN Input. you can enter sides to test it. just leave a space between them (i.e. 3 8 -2). this question will be brought on our midterm so i want to make sure i did it absolutely correct now and that no errors slip past me.
Last edited: