Ok. sorry to bother you guys with a newb question.
Ok ive just started learning c++. Acctualy i tried to start for like a year ago but I didnt have enough time to learn it.
Anyway. here is my problem.
"Write a program that asks for a number and a power. Write a recursive function that takes the number to the power. Thus, if the number is 2 and the power is 4, the function will return 16"
That is an exercise from my book.
So far i have this
Code:
#include <iostream>
#include <stdlib.h>
float myFunc(unsigned short int x, unsigned short int y);
int main()
{
unsigned short int x = 0;
unsigned short int y = 0;
float z;
std::cout<<"Write a exponent: ";
std::cin>>x;
std::cout<<"\nNow write a number: ";
std::cin>>y;
z = myFunc(x,y);
std::cout<<"\n the answer is:" << z;
system("pause");
return 0;
}
float myFunc(unsigned short int x, unsigned short int y)
{
}
I don't have a clue of what to put in my function. everytime i try it just ends up with some sort of a loop.
Don't laugh, i just started reading this book a couple of hours ago. And this recursive functions is hard for me to understand.