; errors

I need help debugging this program. It keeps giving me ";" errors saying they are missing in front of the if and else statement, and the right curly bracket. Yet I'm still not finding the errors. any help would be appreciated.

// recursive function of base and exponet

#include

using std::cin;
using std::cout;
using std::endl;

long power(int,int);

int main ()

{

int base, exponet; // initailize base, exponet;

cout << "Enter base as an integer: ";
cin >> base; // get integer from user;
cout << "Enter exponent as an integer: ";
cin >> exponet; // get exponet from user;
cout << base << " is the power rasied to " << exponet << (base, exponet) << endl;

return 0;

} // end funtion main;

long power( int base, int exponet);

if (exponent==1) // check for base case;

return base;

else

return base * power ( base, exponet-1); // recursive step;
}




Comments

  • [code]// recursive function of base and exponet

    #include

    using std::cin;
    using std::cout;
    using std::endl;

    long power(int,int);

    int main ()

    {

    int base, exponet; // initailize base, exponet;

    cout << "Enter base as an integer: ";
    cin >> base; // get integer from user;
    cout << "Enter exponent as an integer: ";
    cin >> exponet; // get exponet from user;
    cout << base << " is the power rasied to " << exponet << (base, exponet) << endl;

    return 0;

    } // end funtion main;

    [red]long power( int base, int exponet)
    {
    if (exponent==1) // check for base case;

    return base;

    else

    return base * power ( base, exponet-1); // recursive step;
    }[/red][/code]

    Steph.
  • : [code]// recursive function of base and exponet
    :
    : #include
    :
    : using std::cin;
    : using std::cout;
    : using std::endl;
    :
    : long power(int,int);
    :
    : int main ()
    :
    : {
    :
    : int base, exponet; // initailize base, exponet;
    :
    : cout << "Enter base as an integer: ";
    : cin >> base; // get integer from user;
    : cout << "Enter exponent as an integer: ";
    : cin >> exponet; // get exponet from user;
    : cout << base << " is the power rasied to " << exponet << [blue]power[/blue](base, exponet) << endl;
    :
    : return 0;
    :
    : } // end funtion main;
    :
    : [red]long power( int base, int exponet)
    : {
    : if (exponent==1) // check for base case;
    :
    : return base;
    :
    : else
    :
    : return base * power ( base, exponet-1); // recursive step;
    : }[/red][/code]
    :
    : Steph.
    :
  • : [code]// recursive function of base and exponet
    :
    : #include
    :
    : using std::cin;
    : using std::cout;
    : using std::endl;
    :
    : long power(int,int);
    :
    : int main ()
    :
    : {
    :
    : int base, exponet; // initailize base, exponet;
    :
    : cout << "Enter base as an integer: ";
    : cin >> base; // get integer from user;
    : cout << "Enter exponent as an integer: ";
    : cin >> exponet; // get exponet from user;
    : cout << base << " is the power rasied to " << exponet << (base, exponet) << endl;
    :
    : return 0;
    :
    : } // end funtion main;
    :
    : [red]long power( int base, int exponet)
    : {
    : if (exponent==1) // check for base case;
    :
    : return base;
    :
    : else
    :
    : return base * power ( base, exponet-1); // recursive step;
    : }[/red][/code]
    :
    : Steph.
    :
    Thanks Steph, that did the trick.
  • : : [code]// recursive function of base and exponet
    : :
    : : #include
    : :
    : : using std::cin;
    : : using std::cout;
    : : using std::endl;
    : :
    : : long power(int,int);
    : :
    : : int main ()
    : :
    : : {
    : :
    : : int base, exponet; // initailize base, exponet;
    : :
    : : cout << "Enter base as an integer: ";
    : : cin >> base; // get integer from user;
    : : cout << "Enter exponent as an integer: ";
    : : cin >> exponet; // get exponet from user;
    : : cout << base << " is the power rasied to " << exponet << (base, exponet) << endl;
    : :
    : : return 0;
    : :
    : : } // end funtion main;
    : :
    : : [red]long power( int base, int exponet)
    : : {
    : : if (exponent==1) // check for base case;
    : :
    : : return base;
    : :
    : : else
    : :
    : : return base * power ( base, exponet-1); // recursive step;
    : : }[/red][/code]
    : :
    : : Steph.
    : :
    : Thanks Steph, that did the trick.
    :
    Do not forget to correct the thing that kern68 pointed out.

    Steph.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories