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: orzo 2007-11-02 22:26

I own 4Chan! I AM Anonymous! That's right, suck on that!

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