Triangle Verifier

Triangle Verifier

For any given triangle the sum of 2 the length of any 2 have to be greater than the length of the third side. If this condition is met for all three combinations of sides, the sides can form a triangle.

Make a program that takes 3 inputs from the user for the sides of a triangle and checks if it is a valid triangle.

Use a function verify_triangle to check all 3 sides.

Answer

#include <iostream>

bool verify_triangle(float a, float b, float c)
{
    return (a + b > c) && (a + c > b) && (b + c > a);
}

int main() 
{
    float a, b, c;
    std::cout << "Enter the lengths of the three sides: ";
    std::cin >> a >> b >> c;

    if (verify_triangle(a, b, c))
        std::cout << "The given lengths can form a triangle.\n";
    else
        std::cout << "The given lengths cannot form a triangle.\n";
}
Questions