0

I am trying to implement the Valid Triangle code, however for some reason I am always getting an unused variable error for the x,y, and z variables in the main function. How do I fix?

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

bool valid_triangle(float a, float b, float c);

int main(void)
{


  printf("Give me a real number: ");
  float x = GetFloat(); 

  printf("Give me a real number: ");
  float y = GetFloat(); 

  printf("Give me a real number: ");
  float z = GetFloat(); 

 bool valid_triangle(float x, float y, float z);


}

bool valid_triangle(float a, float b, float c)
   {
  if (a <= 0 || b <= 0 ||c<=0)
  {
        return false;
  }

  if ((a+b<=c) || (a+c<= b) || (b + c<=a))
  {
  return false;
  }
  return true;
   }
0
bool valid_triangle(float x, float y, float z); // Line 20

The above line does not call valid_triangle, it just declares it. This is no different from the function prototype you wrote on line 5. If you want to call valid_triangle you should do it like so:

valid_triangle(x,y,z);

Or, if you want to use it's return value:

bool is_valid = valid_triangle(x,y,z);
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .