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));
}
#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));
}