Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-13
14
Medium Priority
?
292 Views
Last Modified: 2010-04-15
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
Comment
Question by:deepthiji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 11

Accepted Solution

by:
griessh earned 1600 total points
ID: 11796497
Hi deepthiji,

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

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



======
Werner
0
 
LVL 11

Expert Comment

by:griessh
ID: 11796504
and since you are not returning a value it should be

areaperi(int,float*,float*);
0
 
LVL 11

Expert Comment

by:griessh
ID: 11796509
^%&^%&* ... 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!

 
LVL 11

Expert Comment

by:griessh
ID: 11796552
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
 
LVL 3

Author Comment

by:deepthiji
ID: 11796576
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
 
LVL 3

Author Comment

by:deepthiji
ID: 11796581
Also what you mean by "^%&^%&* ... again:" ?
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 total points
ID: 11796631
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
 
LVL 11

Expert Comment

by:griessh
ID: 11796632
>> "^%&^%&* ... 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
 
LVL 3

Author Comment

by:deepthiji
ID: 11796673
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
 
LVL 11

Expert Comment

by:griessh
ID: 11796728
I don't know how good this site is, I found it some time ago: http://www.geocities.com/learnprogramming123/C.html
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11796751
ooooh, again Error "Type mismatch in redeclaration of areaperi(int float..
0
 
LVL 3

Author Comment

by:deepthiji
ID: 11796768
#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
 
LVL 86

Expert Comment

by:jkr
ID: 11796809
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
 
LVL 3

Author Comment

by:deepthiji
ID: 11796841
Thanks once again, This is really a good site, You guys are doing a great job.
thanks a loooooooooooooooooooot
deep
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question