Solved

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

Posted on 2004-08-13
14
267 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
  • 6
  • 6
  • 2
14 Comments
 
LVL 11

Accepted Solution

by:
griessh earned 400 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 100 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-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.

773 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