dankilman
March 1st, 2008, 02:39 PM
Hello there codeguru gurus...
here is my code:
#include <iostream>
using namespace std;
double sqrtOfTwo(int counter)
{
if (counter==0)
return 0;
else
{
counter--;
return 1.0/(2.0+sqrtOfTwo(counter));
}
}
int main()
{
cout << rec(10); // doesn't really matter what number comes here
return 0;
}
when i run this code the output will be : 0.414214 , which is shorter than what i'd expect to receive, having declared this function as a double, not as a float. this may be something i simply do not understand in the way variable types work. either way, i'd really appreciate details regarding this issue.
here is my code:
#include <iostream>
using namespace std;
double sqrtOfTwo(int counter)
{
if (counter==0)
return 0;
else
{
counter--;
return 1.0/(2.0+sqrtOfTwo(counter));
}
}
int main()
{
cout << rec(10); // doesn't really matter what number comes here
return 0;
}
when i run this code the output will be : 0.414214 , which is shorter than what i'd expect to receive, having declared this function as a double, not as a float. this may be something i simply do not understand in the way variable types work. either way, i'd really appreciate details regarding this issue.