This is from the functions lecture on a valid triangle. I'm not getting any error messages but I can't figure out why the
bool valid_triangle (float x, float y, float z)
function is not working. Any help would be appreciated. Thank you.
'''
#include <stdio.h>
#include <cs50.h>
// declare functions
bool valid_triangle (float x, float y, float z);
int main(void)
{
// ask user for input
printf("Give me the first side of the triangle:\n ");
float x = get_float("");
printf("Give me the second side of the triangle:\n ");
float y = get_float("");
printf("Give me the third side of the triangle:\n ");
float z = get_float("");
}
bool valid_triangle (float x, float y, float z)
{
// check that all sides are positive
if (x <= 0 || y <= 0 || z <= 0)
{
return false;
}
// check that sum of any two sides is greater than the third
if ((x + y <= z) || (x + z <= y) || (y + z <= x))
{
return false;
}
// if both tests are passed, we have a triangle
return true;
}