Power Function

I'm writing a Program that takes x and raises it to the power of y. I'm also trying to make and call my own function called mypow(). This is what I have so far:

// Dannika
// A program that calculates x raised to the y power.

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

int mypow(int, int);
{


int main()
{
int x;
int y;
int sum;
int mypow(int, int);

cout << "I will raise an integer to the power of another. " << endl;

cout << "Please enter my first integer or -1 to quit: " << endl;

cin >> x;

cout << "Please enter an integer to raise: " << endl;

cin >> y;

int sum = mypow(int , int);

cout << " Your answer is : " << mypow(x,y) << endl;
return 0;
}
int mypow(int x , int y);
{

int prod = 1;
int j;

for (int j = 1; int j <= int y; int j++)
{
prod = prod * x;
}
return prod;
}

I need to understand why my debugger keeps saying:1>Lab_7_B.cpp
1>f:\lab7b\lab7b\lab_7_b.cpp(9) : error C2447: '{' : missing function header (old-style formal list?)
1>f:\lab7b\lab7b\lab_7_b.cpp(46) : fatal error C1004: unexpected end-of-file found
1>Build log was saved at "file://f:\Lab7B\Lab7B\Debug\BuildLog.htm"
1>Lab7B - 2 error(s), 0 warning(s)
It looks you errors are
1
2
int mypow(int, int);
{


That brace is not needed since you are only referring to the function prototype. Also
int mypow(int, int); is incorrect and should be erased. By the way, you have declared two variables called sum; you only need one of them.

In your for loop, you don't need to keep declaring int variables. Just declare j once. Here is what your for loop should look like. Keeping in mind you have already declared j before the loop..
for (j = 1; j <= y; j++)

P.S. In the future, be sure to post your code in [ code] [/code] tags so we can read your code easier.
Last edited on
Topic archived. No new replies allowed.