Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- bool valid_triangle(float side1, float side2, float side3);
- int main ()
- {
- printf("Please give me a length: ");
- float x= GetFloat();
- printf("Please give me another length: ");
- float y= GetFloat();
- printf("Please give me the final length: ");
- float z= GetFloat();
- if (bool valid_triangle = true)
- {
- printf("If you have a triangle with lengths %f, %f, and %f it will be fine!", x, y, z);
- }
- }
- bool valid_triangle(float x, float y, float z)
- {
- //check for positive
- if(x < 1 || y< 1 || z< 1)
- {
- return false;
- }
- //check for two sides are greater
- if((x + y <= z) || (y + z <= x) || (x + z <= y))
- {
- return false;
- }
- //if you passed the test congrats! bc..
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement