How many trees can they plant

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:

#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

const double PI = 3.14159;

int main()
{
double length;
double radius;
double space;

cout<< fixed << showpoint << setprecision(2);

cout<< "Enter in the length of the yard: ";
cin>> length;
cout<< endl;

cout<< "Enter in the radius of a full grown tree: ";
cin>> radius;

cout<< "The number of trees you can plant in the yard is: " << length / (radius * radius);
cout<< endl;
space = (length /12) / radius;
cout<< "The space between each tree is: " << space;

return 0;

}
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
n=(int)((length+space)/(2*radius+space))

Last edited on
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.
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).
Thank you looks like that is what I needed .... again thank you.
Topic archived. No new replies allowed.