Share
Explore BrainMass

function convert Length

Write a function convertLength() that receives a real value and two strings inUnits and outUnits, then converts the value given in inUnits to the equivalent metric value in outUnits and displays this value. The function should carry out the following conversions:
inUnits outUnits
I c (inches to centimeters; 1 in. = 2.54001 cm)
F c (feet to centimeters; 1 ft = 30.4801cm)
F m (feet to meters; 1 ft = 0.304801 m)
Y m (yards to meters; 1 yd = 0.914402 m)
M k (miles to kilometers; 1 mi = 1.60935 km)

Also write a driver program to test your function. What happens if you enter units other than those listed?

Solution Summary

Write a function convertLength() that receives a real value and two strings inUnits and outUnits, then converts the value given in inUnits to the equivalent metric value in outUnits and displays this value.

$2.19