Advertisement
BaSs_HaXoR

Check if L3 is hypotenuse C++ (pythagorean-theorem)

Dec 13th, 2014
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include "stdafx.h"//used for Visual Studio Prebuilt header
  2. #include <stdio.h>//used for getline
  3. #include <cmath>//used for pow //pow == Power to a # ->> Used for the function:// http://www.virtualnerd.com/algebra-1/radical-expressions-equations/pythagorean-theorem/pythagorean-theorem-examples/pythagorean-theorem-definition
  4.  
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7.     int L1 ;
  8.         int L2 ;
  9.         int L3;
  10.         string L1s;
  11.     while (true)
  12.     {
  13.         system("color 0a");
  14.         cout<<"Please input length of triangle side 1: ";
  15.         cin >> L1;
  16.         cout<<"Please input length of triangle side 2: ";
  17.         cin >> L2;
  18.         cout<<"Please input length of triangle side 3: ";
  19.         cin >> L3;
  20.         if(L1 < L3 && L2 <L3)/*checks if the two angles that make up the triangle are less than the L3 angle == L3 is the hypotenuse.*/
  21.         {
  22.             int L1pyh = pow(L1, 2);
  23.             int L2pyh = pow(L2, 2);
  24.             int L3pyh = pow(L3, 2);
  25.             if(L1pyh + L2pyh == L3pyh) //pythagorean-theorem
  26.             {
  27.                 cout<<true<<endl;;
  28.                 getline(cin, L1s);
  29.             }
  30.             else
  31.             {
  32.                 system("color 0e");
  33.                 cout<<false<<endl;;
  34.                 getline(cin, L1s);
  35.             }
  36.         }
  37.         else
  38.         {
  39.             system("color 0");
  40.             cout<<"Not a right angle triangle!\n";
  41.             system("cls");
  42.         }
  43.         cout<<" ";
  44.         getline(cin, L1s);
  45.         system("color 0f");
  46.         cout<<"Credits: BaSs_HaXoR";
  47.         getline(cin, L1s);
  48.         system("cls");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement