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:
}
1
Expert's answer
2019-11-04T15:55:33-0500
Dear Messie , your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment