Solved

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

Posted on 2004-08-13
14
270 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 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
Technology Partners: 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 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C: GetDiskFreeSpaceEx() for default drive 14 120
C#, VS15, StructLayout 1 135
placing a checked in the checklistbox based on the value in database table. 3 47
MySQL recovery 7 33
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

730 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