diff --git a/src/convert_C_to_F.c b/src/convert_C_to_F.c new file mode 100644 index 0000000..ddbdd3e --- /dev/null +++ b/src/convert_C_to_F.c @@ -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; +} + + diff --git a/src/convert_C_to_F.h b/src/convert_C_to_F.h new file mode 100644 index 0000000..3981936 --- /dev/null +++ b/src/convert_C_to_F.h @@ -0,0 +1,7 @@ + +#ifndef THEADMIRALS_CONVERT_C_TO_F_H +#define THEADMIRALS_CONVERT_C_TO_F_H + +float convert_temperature(float value, char from_unit, char to_unit); + +#endif //THEADMIRALS_CONVERT_C_TO_F_H