-3

An error pops up for every one of the functions I've defined:

C:\Users\ALVARO~1\AppData\Local\Temp\cc7yNnth.o Ejercicio.cpp:(.text+0xe0): undefined reference to `circ(float, float)'

Here is my code:

float circ(float pi, float radio);
float cuad(float lado);
float rect(float l1, float l2);
float triang(float b, float h);

int main () {
    float pi=3.14;
    char opc;
    printf("Introuce 1 para ciculo");
    printf("2 para cuadrado");
    printf("3 para rectangulo");
    printf("4 para triangulo");
    scanf("%c", &opc);
    while(opc != 4)

    switch(opc) {
        case 1:
            float radio;
            printf("Introduce el valor del radio: ");
            scanf("&f", radio);
            printf("El area del circulo es: %f", circ(pi, radio));
            system("pause");

        case 2:
            float lado;
            printf("Introduce el valor del radio: ");
            scanf("&f", lado);
            printf("El area del cuadrado es: %f", cuad(lado));
            system("pause");

        case 3:
            float ancho, largo;
            printf("Introduce el valor del ancho: ");
            scanf("&f", ancho);
            printf("Introduce el valor del largo: ");
            scanf("&f", largo);
            printf("El area del rectangulo es: %f", rect(ancho, largo));
            system("pause");

        case 4:
            float base;
            float altura;
            printf("Introduce el valor de la base: ");
            scanf("&f", base);
            printf("Introduce el valor de la altura: ");
            scanf("&f", altura);
            printf("El area del triangulo es: %f", triang(base, altura));
            system("pause");
    }
}

What's going wrong?

Das_Geek
  • 2,775
  • 7
  • 20
  • 26

2 Answers2

1

You have declared but not implemented the function

float circ(float pi, float radio);

e: What you want can be accomplished with: (i assume circle area)

float circ(float pi, float radius) {
    return pi * (radius * radius);
}

By the way you have a M_PI constant defined in the math header. You could have your function defined as follow:

#include <math.h>

float circ(float radius) {
    return M_PI * (radius * radius);
}

If you can try to code in english so that everyone can understand your thought process better.

0

every of the functions I defined, no! Every function you declared but not defined.

A declaration is something that let the compiler verify you use the thing correctly.

A definition is the construction of the thing; for a function associates the prototype of the function to the code of it. A definition is also a declaration.

float rect(float l1, float l2); is a declaration. The compiler then know that you can pass two floats and get in return a float from a call.

float rect(float l1, float l2) { return l1*l2; } is a definition. Thus the compiler knows what instruction are to be executed when the function is called.

There is also some other errors. scanf must be used like:

scanf("%f",&radio);

"%f" is the format specifier to mean that a string representing a floating point number must be readable from the input and that the value must be stored in radio (thus prefix & to mean at the address of).

Also use break on every case of your switch like:

switch(...) {
case ...:
    ...
    break;
case ...:
    ...
    break;
}

You can omit break but this is probably not what you want to do...

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69