Question
I am trying to find the area of a triangle using the following code. I am supposed to get the following input values but I
I am trying to find the area of a triangle using the following code. I am supposed to get the following input values but I get completely different values than the ones shown below. What is wrong with my code?
5, 2, 1 (Invalid) 1, 1, 3 (invalid) 1, 3, 1 (invalid) 5, 5, 5 (Valid, 10.83) 3, 4, 5 (Valid, 6.00) 9, 10, 10 (Valid, 40.19)
The code:
*/
#include
#include
#include
#include
using namespace std;
int main() {
double side1;
double side2;
double side3;
double s , area;
bool programOn = true;
while (programOn == true)
{
do
{
cout << "Enter Sides of The Triangle: ";
cin >> side1 >> side2 >> side3;
if ((side1 + side2) > side3 && (side1 + side3) > side2 && (side2 + side3) > side1)
{
cout << "Valid" << endl;
}
else
{
cout << "Invalid" << endl;
}
}
while ((side1 + side2) <= side3 && (side2 + side3) <= side1 && (side1 + side3) <= side2);
double s = (side1 + side2 + side3) / 2.0;
cout << "Area : " << sqrt(s*(s-side1)*(s-side2)*(s-side3));
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started