Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Little help here for a noob?

Name: orzo 2007-11-02 22:23

I'm just starting C++ and I'm having the worst time getting this little thing I wrote to run. It's supposed to take two variables from the user, one as a number and another to multiply it to the power of. It compiles fine and everything but when it's supposed to call the function it crashes. Anyone have any ideas why this is? Thanks in advance.

#include <cstdlib>
#include <iostream>

using namespace std;
unsigned int powered(unsigned int, unsigned int);

int main ()
{
    unsigned int number, power, anwser;
   
    cout << "Enter a number: ";
    cin >> number;
    cout << "Enter a power: ";
    cin >> power;
    anwser = powered(number,power);
    cout << "The awnser is: " << anwser << endl;
    char response;
    cin >> response;
    return 0;
}

unsigned int powered(unsigned int a, unsigned int b)
{
         if(a == 1)
         return a;
         else
         return (a * powered(a,b-1));
}

Name: Anonymous 2007-11-02 22:27

>>1
Either this is your homework and we don't want to do it for you, or you're learning C++ voluntarily and you need to stop it now.

When what is supposed to call what function it crashes with what error message?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List