(Sides of a Triangle) Write a program that reads three nonzero double values and deter- mines and prints whether they could represent the sides of a triangle.
What will be an ideal response?
```
// Determine whether three values could represent the sides of a triangle.
#include
using namespace std;
int main()
{
double side1; // length of side 1
double side2; // length of side 2
double side3; // length of side 3
bool isTriangle = false; // whether the sides can form a triangle
// get values of three sides
cout << "Enter side 1: ";
cin >> side1;
cout << "Enter side 2: ";
cin >> side2;
cout << "Enter side 3: ";
cin >> side3;
// test if the sides can form a triangle
if ( side1 + side2 > side3 )
{
if ( side2 + side3 > side1 )
{
if ( side3 + side1 > side2 )
isTriangle = true;
} // end inner if
} // end outer if
// display result
if ( isTriangle )
cout << "These could be sides to a triangle." << endl;
else
cout << "These do not form a triangle." << endl;
} // end main
```
You might also like to view...
Quick Start tables are created from templates
Indicate whether the statement is true or false
________ software helps to protect your computer from various types of malware.
A. Anti-malware B. Encryption C. Backup D. Firewall
The ____ attribute of a hotspot specifies a descriptive name for the image map.
A. Name B. Target C. Alt D. Map
In Office 2013, the Help button is located on the Ribbon
Indicate whether the statement is true or false