المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Stack Overflow



C# Programming
05-20-2009, 11:30 AM
Hey, I'm trying to create a program that would figure out how many times to fold a sheet of paper to get to the moon using recursion and I'm getting a Stack Overflow Error, any thoughts?


const float PageWidth = 0.1F;
const float distanceToMoon = 380000000000;
static void Main(string[] args)
{
Console.WriteLine("You have to fold the sheet of paper " + Moon(1) + " times to get to the moon");
Console.ReadLine();
}
static float Moon(float times)
{
return ((times * PageWidth) > distanceToMoon ? times : Moon(times+1));
}