Code Wars V
     

Program / Task Name:

   Height of a Rainbow

Level:

 

 Novice

Point Value:

 

 2

 
Task Description

How tall is a rainbow?

Because of the way in which light is refracted by water droplets, the angle between the level of your eye and the top of the rainbow is always the same.  If you know the distance to the rainbow, you can multiply it by the tangent of that angle to find the height of the rainbow.

The magic angle is 42.3333333 degrees.

The C++ standard library works in radians, so you may have to convert the angle to radians with the formula:

Radians = degrees x pi/180 (where pi = 3.14159265)

Through the header file cmath, the C++ standard library provides a tangent function named tan.  This is a value returning function that takes a floating-point argument and returns a floating-point result.

x=tan(someAngle);

To determine the height of the rainbow, multiply the tangent by the distance to the rainbow.

Write a program to determine the height of a rainbow.

Program Input

Please prompt the judge to enter the distance to the rainbow (in meters) as shown below:

Enter the distance to the rainbow (in meters): 52

You can assume that:

  • The value entered will be a number, and

  • The value will be an integer (the judge will not enter a decimal number, i.e. 52.3)

Program Output

After reading the distance to the rainbow, determine the height of the rainbow and print it out to 4 decimal places.

The height of the rainbow is 47.3717 meters.

 

hp Code Wars
Hello -- Dominos?...
   
  (c) 2004 Hewlett-Packard Company