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)); 
    }
}

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

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

Thank you for pointing that out!:)

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)); 
    }
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.