problem: I'm making a triangle. side lengths will be provided by user. thats it.
only rules : any 2 side lengths of the triangle must be greater than 3rd side length. no sides can be <= 0.
if these conditions are met the code prints TRUE. if not, prints FALSE.
I wrote this code. I can't return the value where it should be. I can't use the bools correctly and can't return a value.
error message: triangle.c:11: error: comparison between pointer and integer ('bool ()(float, float, float)' and 'int') [-Werror] if (valid_triangle == true) // triangle.c:13: error: format specifies type 'int' but the argument has type 'bool ()(float, float, float)' [-Werror,-Wformat] printf("triangle side lengths are %i", valid_triangle);
GitHub link of the code (triangle.c)
1 #include <cs50.h>
2 #include <stdio.h>
3 bool valid_triangle(float a, float b, float c);
4 int main(void)
5{
6 printf("give me the sides of triangle: ");
7 float a = get_float();
8 float b = get_float();
9 float c = get_float();
10 bool i = valid_triangle(a, b, c);
11 if (valid_triangle = true)
12 {
13 printf("triangle side lengths are %i", valid_triangle);
14 } // I tried %b, %s etc. didnt work.
15 if (valid_triangle = false)
16 {
17 printf("triangle side lengths are %i", valid_triangle);
18 } // I tried %b, %s etc. didnt work.
19 }
20 bool valid_triangle(float a, float b, float c)
21 {
22 if (a <= 0 || b <= 0 || c <=0) // check for all positive sides
23 {
24 return false;
25 }
26 if (a + b <= c) || (a + c <= b) || (c + b <= a) // check that sum of any two sides are greater than third side.
27 {
28 return false;
29 }
30 return true; // if we passed both tests, result is true.
31 }