Hey new member here. I'm having trouble with this C++ problem.
The question is:
Write program to ask user for length of backside of lot(all 100 lots are same size), then ask user for radius of fully grown tree, and then ask user how much space they want between the fully grown trees. Program should determine # of trees in one lot, and then # of trees in all 100 lots.
The part where I'm stuck on is incorporating the space in between trees. Here's the code I've got so far.
#include <iostream>
usingnamespace std;
int main()
{
int lotLength, radiusTree, spaceTrees;
cout << "What is the back side length of the lot?(in feet) " << endl;
cin >> lotLength;
cout << "What is the radius of a fully grown tree?(in feet) " << endl;
cin >> radiusTree;
cout << "How much space would you like between the trees?(in feet) " << endl;
cin >> spaceTrees;
int lotTrees;
lotTrees = lotLength / (radiusTree * 2);
cout << "The trees needed to fill one side is: " << lotTrees << endl;
int totalLotTrees;
totalLotTrees = lotTrees * 100;
cout << "The total amount of trees needed to fill 100 lots is: ";
cout << totalLotTrees << endl;
return 0;
}
I believe your calculations, are wrong. I would take the radiusTree added to spaceTrees, then, take the lotLength and divide it by that result, minus 1.
1 2 3 4
int distance = spaceTrees + radiusTree;
lotTrees =( lotLength / distance)-1;// Next one would be on the fence
// so, subtract it
I'm confused. spaceTrees = the distance the user wants in between each tree. So looking at that snippet of code you posted makes me question where you got distance from.
ARGH I've been on this problem for so long and I can't figure it out. Though I do have to admit, it is rather exciting and makes me want to learn more and more. :)
#include <iostream>
usingnamespace std;
int main()
{
float lotLength, radiusTree, spaceTrees;
cout << "What is the back side length of the lot?(in feet) " << endl;
cin >> lotLength;
cout << lotLength << endl;
cout << "What is the radius of a fully grown tree?(in feet) " << endl;
cin >> radiusTree;
cout << radiusTree << endl;
cout << "How much space would you like between the trees?(in feet) " << endl;
cin >> spaceTrees;
cout << spaceTrees << endl;
float n = (float)spaceTrees + 2 * (float)radiusTree;
float l = (float)lotLength - (float)spaceTrees;
int lotTrees = l / n; //int for a whole number.
cout << "The trees needed to fill one side is: " << lotTrees << endl;
int totalLotTrees;
totalLotTrees = lotTrees * 100;
cout << "The total amount of trees needed to fill 100 lots is: ";
cout << totalLotTrees << endl;
return 0;
}
Keep it int. You won't grow half a tree very successfully.
You have radius, so diameter (width of a tree) is twice that.
You plant the first tree at the corner of a lot, just a radius from border (so we won't leave space between our tree and the neighbour's lot). Or should you leave space? I have no idea.
What remains for the rest of the trees? ltheRest = lotLength - diameter;
How much would adding one more tree consume from the remaining space? oneMore = spaceTrees + diameter;
We have deduced that N*oneMore <= theRest. Can you solve the N?
I bet that you won't plant just one line of trees per lot. Is a lot perhaps a square piece of land?
My comprehension is that the repartition is like this :
-RR-RR-RR-...-RR-RR-RR-
where - is the space between trees and R the radius.
line 20, u get ride of one of the - (starting or ending).
U re right to reconvert into int, but it is important to make the previous operations with floats. As U did is OK for me.