|
@ -0,0 +1,19 @@ |
|
|
|
|
|
#include "stdio.h" |
|
|
|
|
|
#include "convert_C_to_F.h" |
|
|
|
|
|
|
|
|
|
|
|
float convert_temperature(float value, char from_unit, char to_unit) { |
|
|
|
|
|
float result; |
|
|
|
|
|
|
|
|
|
|
|
if (from_unit == 'c' && to_unit == 'f') { |
|
|
|
|
|
result = (value * 9 / 5) + 32; // Celsius to Fahrenheit |
|
|
|
|
|
} else if (from_unit == 'f' && to_unit == 'c') { |
|
|
|
|
|
result = (value - 32) * 5 / 9; // Fahrenheit to Celsius |
|
|
|
|
|
} else { |
|
|
|
|
|
printf("Invalid units or conversion not supported.\n"); |
|
|
|
|
|
result = -1; // Error code |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|