Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a program which calculte the power of a number
example 2^5 = 32

program

C++
#include<stdio.h>
#include<conio.h>

void main(){
	int a,b,c;
	int power();
	printf("base value : ");
	scanf("%d",&a);
	printf("power value : ");
	scanf("%d",&b);

	c=power(a,b);
	printf("value of a power b =%d",c);
	getch();
	}


when i compile this program an error comes
Error at line 12 : Extra Parameter to call power()


But in this program no error comes

Program

C++
int power(int x,int y){
	int k,l,m=1;
	k=x;l=y;
	for(int i=0;i<l;i++)
		m = m*k;
	return(m);
}
void main(){
	int a,b,c;
	
	printf("base value : ");
	scanf("%d",&a);
	printf("power value : ");
	scanf("%d",&b);

	c=power(a,b);
	printf("value of a power b =%d",c);
	getch();
	}


I think there is a problem in function declaration in 1st program.
but according to book function can be declared without specifying arguments. So i declared as "int power();"

Please tell what error means and where is the problem.
Posted
Updated 24-Aug-10 21:16pm
v2
Comments
Niklas L 25-Aug-10 4:12am    
There's no need for the local variables k and l in your power function. You already have x and y.

1 solution

IF you look at the differences between the two programs, why do you notice ? I notice this:

int power();

The error message is a bit weird, but I think it's totally confused because your syntax makes no sense. Try

int power;

Or just get rid of that line, I'm not noticing that it does anything.

Does the power method exist in the first program and you just didn't show it ?
 
Share this answer
 
Comments
pradeep_bhadani 25-Aug-10 8:10am    
when i try int power;
then error comes : cal of non function at line 12

and this is correct as we have to declare a function before using it. we can define later but we have to declare it first.

and if i omit int power();
the error comes : Function power should have prototype

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900