Browse Source

added Celsius to Fahrenheit converter

remotes/origin/develop
Sandro Welte 11 months ago
parent
commit
7d03f56fe9
  1. 19
      src/convert_C_to_F.c
  2. 7
      src/convert_C_to_F.h

19
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;
}

7
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
Loading…
Cancel
Save