Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago