0

Hello,

I am working on a non-recursive function that computes a to the power n. I have one error which is cpp(23) : error C3861: 'mypower': identifier not found

#include "stdafx.h"
#include "stdio.h"
 
double power(float a, int n); // function prototype//
 
 
int main (void)
{
    float a;
    int n;
	int power;


    printf("\n enter a value of a\n");
	scanf ("%d", &a);
	printf("\n enter value of n\n");
	scanf ("%d", &n);
	power= mypower (a,n);
    printf("The result is %d\n", power);
	
	 return 0;
}
double mypower(float a, int n)
{
if (a==0.0) 
    {
        return 0.0;
 
    }
    else if(n==0)
    {
        return 1.0;
     }
    else if (n>0)
    {
        return( a* mypower(a,n-1));
    }
    else
    {
        return (1.0/ mypower(a,-n)); 
    }
}
5
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by devnar
0

>cpp(23) : error C3861: 'mypower': identifier not found
Do you know what that cpp means?
You are compiling the code as a C++ program.
C code must end as *.c

Anyway. The error says that you are not prototyping the function mypower correctly.

0

There is also the incidental concern that your function is recursive, which does not meet the requirement to be non-recursive.

0

I realized this the function was not recursive as I am trying to fix it I have one error which is (29) : error C2447: '{' : missing function header (old-style formal list?)

#include "stdafx.h"
#include "stdio.h"
 
int mypower(float a, int n); 
 
 
int main (void)
{
    float a;
    int n;
	int power;


    printf("\n enter a value of a\n");
	scanf ("%d", &a);
	printf("\n enter value of n\n");
	scanf ("%d", &n);
	power= mypower (a,n);
    printf("The result is %d\n", power);
	
	 return 0;
}
int mypower(float a, int n); 
{
if (a==0.0) 
    {
        return 0.0;
 
    }
    else if(n==0)
    {
        return 1.0;
     }
    else if (n>0)
    {
        return( a* mypower(a,n-1));
    }
    else
    {
        return (1.0/ mypower(a,-n)); 
    }
}
0

scanf ("%d", &a); a is declared as a float, so %d should be %f.

Function definition- int mypower(float a, int n); there's no semicolon at the end. (as Salem pointed out.) int power return 0.0; I think power should be declared a float. You might get a warning for that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.