-1

I have problem with this:

parameter1.c: In function ‘main’:
parameter1.c:13:2: error: incompatible type for argument 2 of ‘Countcircumferenceofcircle’
parameter1.c:4:6: note: expected ‘double *’ but argument is of type ‘double’

here is the code:

#include <stdio.h>
#define phi 3.14

void Countcircumferenceofcircle(int radius, double *C) {
    *C = 2*phi*radius;
}

int main (void) {
    int r;
    double Circumference;

    printf("Insert radius:");
    scanf("%d", &r);

    Countcircumferenceofcircle(r, Circumference);
    printf("Circumference=%f\n", Circumference);

    return 0;
}

i need your help to solve this.

Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
Lundu Harianja
  • 443
  • 1
  • 9
  • 17
  • 1
    change to `Countcircumferenceofcircle(r, &Circumference);` – BLUEPIXY Jul 01 '13 at 22:53
  • 3
    See what you did for the `scanf`? Do the same thing for `Countcircumferenceofcircle`. – Mark Ransom Jul 01 '13 at 22:53
  • 1
    Duplicate of the many [expected ‘X’ but argument is of type ‘Y’](http://stackoverflow.com/q/6778384/) questions. The error message says exactly what is wrong. You are calling a function that takes a parameter declared as `double *C`, but you are passing a `double`, which is not the same thing. – Raymond Chen Jul 01 '13 at 23:18
  • 2phi? Most people use the constants in the their favorite language. Look around. There are some you may use. Have fun. – Douglas G. Allen Apr 03 '14 at 13:56

2 Answers2

6

You have to pass the address of the variable, since the function expects a pointer. The result is that the function call modifies your original variable:

double Circumference;

Countcircumferenceofcircle(r, &Circumference);
//                           ^^^

// now Circumference is different!

By the way, this is relatively inelegant and archaic design. It would be much cleaner, and no less efficient, to write:

double circumference(int radius)
{
    return 2.0 * M_PI * radius;
}

int main()
{
    // ...
    double c = circumference(r);
    // ...
}
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
0

On the line 13 of your code use:

Countcircumferenceofcircle(r,&Circumference);

instead of

Countcircumferenceofcircle(r,Circumference);

The function receives a pointer to a double, in the second example you're passing the double itself. In the first one you're passing the address / pointer to your double.

Rudy Matela
  • 6,310
  • 2
  • 32
  • 37