|
@ -0,0 +1,23 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "convert_m_to_ft.h" |
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
|
|
float convert_length(float value, char from_unit, char to_unit) { |
|
|
|
|
|
float result; |
|
|
|
|
|
|
|
|
|
|
|
if (from_unit == 'm' && to_unit == 'f') { |
|
|
|
|
|
result = value * 3.281; // Meters to feet |
|
|
|
|
|
} else if (from_unit == 'f' && to_unit == 'm') { |
|
|
|
|
|
result = value / 3.281; // Feet to meters |
|
|
|
|
|
} else if (from_unit == 'i' && to_unit == 'c') { |
|
|
|
|
|
result = value * 2.54; // Inches to centimeters |
|
|
|
|
|
} else if (from_unit == 'c' && to_unit == 'i') { |
|
|
|
|
|
result = value / 2.54; // Centimeters to inches |
|
|
|
|
|
} else { |
|
|
|
|
|
printf("Invalid units or conversion not supported.\n"); |
|
|
|
|
|
result = -1; // Error code |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|