C++ Program to take a value from the user as input the angles of a triangle and check whether the triangle is valid or not by using the user define functions. Triangle program

Explanation:

  1. Pass-by-Value (isTriangleValidByValue):
    • Function Definition: bool isTriangleValidByValue(int angle1, int angle2, int angle3)
    • This function takes three angles as input parameters by value.
    • It checks if the sum of the three angles equals 180 degrees.
    • If the sum is exactly 180 degrees, it returns true, indicating that the triangle is valid; otherwise, it returns false.
  2. Pass-by-Reference (isTriangleValidByReference):
    • Function Definition: void isTriangleValidByReference(int angle1, int angle2, int angle3, bool &isValid)
    • This function also takes three angles as input, but the result is passed by reference.
    • It calculates whether the sum of the angles is exactly 180 degrees and stores the result in the isValid reference variable.
  3. Main Function (main):
    • The program prompts the user to input three angles of a triangle.
    • It checks if the triangle is valid using both methods and prints the results.

Example Outputs:

Example 1:

Input:

  • First Angle: 60
  • Second Angle: 60
  • Third Angle: 60

Output:

Example 2:

Input:

  • First Angle: 90
  • Second Angle: 45
  • Third Angle: 50

Output:

Example 3:

Input:

  • First Angle: 90
  • Second Angle: 60
  • Third Angle: 30

Output: