Menu

[solved] – Question 98003

Suppose an alien giant walks with decreasing steps (stride length). Each step is half of his last step. Write a function to calculate how far the alien giant can go with known steps if the giant’s very step is one mile. Test your program with different numbers of steps to observe the results. With how many steps can the alien giant go more than two miles? Extra points will be given if you can find the result mathematically.
(Hint: Total distance = 1 + 1/2 + 1/4 + 1/8 + …)
double walk(int steps)
{
double totalDistance;
//Fill in here

return totalDistance;
}

int main()
{
//Sample function calls. You might change the number of steps to test how far the giant can go
cout << “With 10 steps the giant walked ” << walk(10) << ” miles.” << endl;
cout << “With 30 steps the giant walked ” << walk(30) << ” miles.” << endl;
return 0:
}

Expert Answer


OR


Leave a Reply

Your email address will not be published. Required fields are marked *