- #1
needOfHelpCMath
- 72
- 0
Simple geometry can compute the height of an object from the object's shadow length and shadow angle using the formula: tan(angleElevation) = treeHeight / shadowLength. Given the shadow length and angle of elevation, compute the tree height.
My outputs
✖ Testing with shadowLength = 17.5, angleElevation = 0.11693706
Expected value: 2.05578
Your value: 1.87656
Tests aborted.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main( ) {
double treeHeight = 0.0;
double shadowLength = 0.0;
double angleElevation = 0.0;
angleElevation = 0.11693706; // 0.11693706 radians = 6.7 degrees
shadowLength = 17.5;
treeHeight = cos(shadowLength) / angleElevation ;
cout << "Tree height: " << treeHeight << endl;
return 0;
}
My outputs
✖ Testing with shadowLength = 17.5, angleElevation = 0.11693706
Expected value: 2.05578
Your value: 1.87656
Tests aborted.