2016-03-20 3 views
-1

Так что я выполняю задание для школы, но я продолжаю получать сообщения об ошибках, и я прочитал несколько потоков, и я не нашел ни одной души, или, может быть, я просто не понимая, что говорится.ошибка несовместимых типов при назначении типа из типа в C

Вот мой код:

#include <stdio.h> 

int main() { 
//declare the variables 
float radius, circumference; 

radius = 0; 

printf ("This program will calculate the circumference of a circle given the radius\n"); 

printf ("Please enter the radius of the circle:\n"); 
scanf ("%f", &radius); 

circumference = calculate_circumference(radius); 

printf ("The circumference of the circle is:\n", circumference); 
return 0; 
} 

float calculate_circumferene (float circle_radius) 
{ 

    float circle_circumference, PI; 

    PI = 3.14159; 

    circle_circumference = 2 * PI * circle_radius; 

    return (circle_circumference); 
} 

Вот сообщения об ошибках, я получаю:

prog.c: In function 'main': 
prog.c:21:18: warning: implicit declaration of function 'calculate_circumference' [-Wimplicit-function-declaration] 
    circumference = calculate_circumference(radius); 
      ^
prog.c:24:10: warning: too many arguments for format [-Wformat-extra-args] 
    printf ("The circumference of the circle is:\n", circumference); 
    ^
/home/j1N8a0/ccUei3id.o: In function `main': 
prog.c:(.text.startup+0x45): undefined reference to `calculate_circumference' 
collect2: error: ld returned 1 exit status 

Любой тип помощи или указал мне в правильном направлении, будет оценен по достоинству!

ответ

2

Вам необходимо объявить функции перед их использованием и соблюдать осторожность при опечатке.

Хотя предоставление дополнительных аргументов для printf() не является вредным, но вы должны использовать спецификатор формата, начиная с %, для печати данных в переменных через printf().

Попробуйте это:

#include <stdio.h> 

/* declare the function to use */ 
float calculate_circumference (float circle_radius); 

int main() { 
    //declare the variables 
    float radius, circumference; 

    radius = 0; 

    printf ("This program will calculate the circumference of a circle given the radius\n"); 

    printf ("Please enter the radius of the circle:\n"); 
    scanf ("%f", &radius); 

    circumference = calculate_circumference(radius); 

    /* add format specifier to print the value */ 
    printf ("The circumference of the circle is: %f\n", circumference); 
    return 0; 
} 

/* add "c" before last "e" of the function name */ 
float calculate_circumference (float circle_radius) 
{ 

    float circle_circumference, PI; 

    PI = 3.14159; 

    circle_circumference = 2 * PI * circle_radius; 

    return (circle_circumference); 
}