Oct 17, 2020 at 9:22pm UTC
I wrote a program that I am not sure if the math is right.
Write a program that prompts the user to input the following:
a. The length of the yard.
b. the radius of a fully grown tree.
c the required space between fully grown trees.
The program out puts the number of trees that can be planted in the
yard and the total space that will be occupied by the fully grown trees.
This is what I have:
using namespace std;
const double PI = 3.14159;
cout<< fixed << showpoint << setprecision(2);
cout<< "Enter in the length of the yard: ";
cout<< "Enter in the radius of a full grown tree: ";
cout<< "The number of trees you can plant in the yard is: " << length / (radius * radius);
space = (length /12) / radius;
cout<< "The space between each tree is: " << space;
Oct 17, 2020 at 9:32pm UTC
Are you planting your trees in a straight line? Or is there some designated shape for the yard?
You appear not to be asking the user for the space between the full-grown trees. Your expression length / (radius * radius) also has the wrong physical dimensions. And why the length / 12?
Your question is too unclear. But if the trees are in a straight line then
Last edited on
Oct 17, 2020 at 9:36pm UTC
Oct 17, 2020 at 9:37pm UTC
Yes, the trees are in a straight line. Not sure why am not asking for the space I am only going by the information in the text above the code and the 12 is just a random number I plugged in.
Oct 17, 2020 at 9:55pm UTC
The question asks you to prompt for length, radius, space ... so why not prompt for length, radius, space?!
Plugging in random numbers seems a bit ... overoptimistic!
Any way, I gave you a formula for the number of trees (in a straight line).
Oct 17, 2020 at 10:06pm UTC
Thank you looks like that is what I needed .... again thank you.