Advertisement
Guest User

CS50 Section 2- Functions

a guest
Jul 6th, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cs50.h>
  2. #include <stdio.h>
  3.  
  4. bool valid_triangle(float side1, float side2, float side3);
  5.  
  6. int main ()
  7. {
  8.     printf("Please give me a length: ");
  9.     float x= GetFloat();
  10.     printf("Please give me another length: ");
  11.     float y= GetFloat();
  12.     printf("Please give me the final length: ");
  13.     float z= GetFloat();
  14.  
  15.     if (bool valid_triangle = true)
  16.     {
  17.         printf("If you have a triangle with lengths %f, %f, and %f it will be fine!", x, y, z);
  18.     }
  19. }
  20.  
  21. bool valid_triangle(float x, float y, float z)
  22. {
  23.     //check for positive
  24.     if(x < 1 || y< 1 || z< 1)
  25.     {
  26.         return false;
  27.     }
  28.     //check for two sides are greater
  29.     if((x + y <= z) || (y + z <= x) || (x + z <= y))
  30.     {
  31.         return false;
  32.     }
  33.     //if you passed the test congrats! bc..
  34.     return true;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement