1

I am making a program that asks the user the length of each side of the triangle and calculates whether or not the side lengths given make a valid triangle. The error is generated on line 24 as you might have seen in the title. I am sorry i am a beginner and thank you in advance Here is the code:

#include <stdio.h>
#include <string.h>

int main(void)
{
    bool valid_triangle(float a, float b, float c);

    float a1 = get_float("a = ");
    float b2 = get_float("b = ");
    float c3 = get_float("c = ");

    if (valid_triangle(a1, b2, c3) == true)
    {
        printf("It is a triangle");
    }

    if (valid_triangle(a1, b2, c3) == false)
    {
        printf("it is not a triangle");
    }

    bool valid_triangle(float a, float b, float c)
    {
        float sum = a + b;

        if (sum > c)
        {
            return true;
        }

        if (sum < c)
        {
            return false;
        }

        if (sum >= 0)
        {
            return false;
        }
    }
}```
JMasterBoi
  • 109
  • 1
  • 3
  • 6
  • 1
    You're trying to define one function inside another. This works in Python, but not in C. Move everything from `bool valid_triangle` to its closing brace to the line above `int main(void)` and try compiling again. – r3mainer May 08 '20 at 00:21

0 Answers0