Problem: write a function named powfun() that raises an integer number passed to it to a positive integer power and displays the result. The positive integer should be the second value passed to the function. Declare the variable used to store the result as a long integer data type to ensure sufficient storage fo rthe result. My interpretation program of this problem is as follows; Please help to sovle this problem

#include <iostream>
#include <cmath>
using namespace std;


int Powfun(int,int);


int main ()
{
	
           { int x,y;
             x = 3;
             y = 4;
      	   
             Powfun((x)(y)) = 81;
      
     
            }
    
  	cin.ignore();

	return 0;


 int Powfun(long int x,y);
 (
   ((x)(y))= 81;

   cout << "The results " << x << y << "is << x << y << endl";

   return;
   
 }

line 3 -- delete it because the program does not use anything in that header file.

move the close brace on line 20 down to the end of the function on line 25 (after the return). Then remove the open brace on line 13 because it is redundent.

remove the semicolon at the end of line 27.

line 29 is just flat out wrong. Delete it. What you need to do here is
1) declare a variable that will hold the result of the calculations and initialize it to 1.
2) create a for loop that counts from 0 to y.
3) multiply the result variable by x on each loop iteration and store this back in the result variable. Almost identical to the way you would do it on with pencil & paper. Do it on paper first so that you can easily visualize the algorithm.

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.