Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

please help,basic C question. ERROR1:"Extra parameter in call" ERROR 2:"Function should return a value"

hi experts please help me,
i am a student and learnning C by myself, i wrote the below program and got these errors.

ERROR 1:Extra parameter in call to areaperi.
ERROR 2:Function should return a value.

#include<stdio.h>
#include<conio.h>
float areaperi(int);
void main()
{
int radius;
float area,perimeter;
printf ("enter the radius");
scanf ("%d",&radius);
areaperi(radius,&area,&perimeter);
printf ("%d\n%d",area,perimeter);
getch();
}
areaperi(int r,float *a,float *p)
{
*a=3.14*r*r;
*p=2*3.14*r;
}

Could anyone explain why i am getting these errors and please guide me the proper way.
thanks in advance. Also is there any "FREE" site where  i can get  sample questions (offcourse 'C' questions) ?
deep
0
deepthiji
Asked:
deepthiji
  • 6
  • 6
  • 2
2 Solutions
 
griesshCommented:
Hi deepthiji,

Your def for areaperi is : float areaperi(int);
change it to

float areaperi(int,float*,float*);



======
Werner
0
 
griesshCommented:
and since you are not returning a value it should be

areaperi(int,float*,float*);
0
 
griesshCommented:
^%&^%&* ... again:

void areaperi(int,float*,float*);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
griesshCommented:
Life is not easy, especially on Fridays :-)

ERROR 1:Extra parameter in call to areaperi.
This error means that after declaring "float areaperi(int);" with only one parameter the compiler was surprised that you passed in three parameters in "areaperi(radius,&area,&perimeter);"

ERROR 2:Function should return a value.
This error means that after declaring "float areaperi(int);" to return a float value the actual implementation "areaperi(int r,float *a,float *p)" didn't do that.
0
 
deepthijiAuthor Commented:
ok.
so i have to add void areaperi(int,float*,float*) right? because i am  passing three variables (radius,area and perimeter) Am i right?

Suppose If i had return some three values and passing three values, then i should have write, int ,int*, int areaperi(int,float*,float*)
is this correct?
If not could you please explain whats the rule?
thanks for the quick reply.
0
 
deepthijiAuthor Commented:
Also what you mean by "^%&^%&* ... again:" ?
0
 
jkrCommented:
Some more info: If you don't specify a return type or 'void', the compiler assumes that the function will return an 'int', thus the error message.
0
 
griesshCommented:
>> "^%&^%&* ... again:"

Sorry, I messed up the posts, so I tried to avoid using inappropriate words :-)

functions only allow you to return ONE value. If you need multiple values you have to either pass them by reference (as you did with float*,float*) or you have to create a structure that contains multiple values and return a pointer to that.
0
 
deepthijiAuthor Commented:
Ok Ok, i got it. thanks a lot for the help. just started learnning C. will take ages to learn the whole thing i guess >)
 Points for both of you, By anychance you have any idea about some Free websites that have sample C question, just for practicing.
thanks
deep
0
 
griesshCommented:
I don't know how good this site is, I found it some time ago: http://www.geocities.com/learnprogramming123/C.html
0
 
deepthijiAuthor Commented:
ooooh, again Error "Type mismatch in redeclaration of areaperi(int float..
0
 
deepthijiAuthor Commented:
#include<stdio.h>
#include<conio.h>
void areaperi(int,float*,float*);
void main()
{
int radius;
float area,perimeter;
printf ("enter the radius");
scanf ("%d",&radius);
areaperi(radius,&area,&perimeter);
printf ("%d\n%d",area,perimeter);
getch();
}
areaperi(int r,float *a,float *p)
{
*a=3.14*r*r;
*p=2*3.14*r;
}

Above is the modified code , Again error"Type mismatch in redeclaration of areaperi(int float..
>(
0
 
jkrCommented:
You need the same return type with both the prototype and the implementation:

 #include<stdio.h>
#include<conio.h>
void areaperi(int,float*,float*);
void main()
{
int radius;
float area,perimeter;
printf ("enter the radius");
scanf ("%d",&radius);
areaperi(radius,&area,&perimeter);
printf ("%d\n%d",area,perimeter);
getch();
}
void areaperi(int r,float *a,float *p)
{
*a=3.14*r*r;
*p=2*3.14*r;
}
0
 
deepthijiAuthor Commented:
Thanks once again, This is really a good site, You guys are doing a great job.
thanks a loooooooooooooooooooot
deep
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now