c-first-steps

a C playground
Index Commits Files Refs README
commit daf9ce7d43403f4c0e320e23f59b99af69f1883e
parent 2196d1b2a4a57d46172b500cec7f08a8e96e3f64
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date:   Thu, 29 Oct 2020 17:18:09 -0300

Little program that converts FAHRENHEIT degrees to CELSIUS degress

Diffstat:
Aej4.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+), 0 deletions(-)
diff --git a/ej4.c b/ej4.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef enum {
+    CELSIUS,
+    FAHRENHEIT
+} escala_t;
+
+typedef float dato_t;
+
+char s[10];
+
+float ftoc(float fahrenheit) {
+    return (((fahrenheit - 32)*5)/9);
+}
+
+void title()
+{
+    printf("---------------------------------------\n");
+    printf("---------------------------------------\n");
+    printf("--- FAHRENHEIT TO CELSIUS CONVERTER ---\n");
+    printf("---------------------------------------\n");
+    printf("---      to exit press Ctrl+D      ----\n");
+    printf("---------------------------------------\n");
+    printf("---------------------------------------\n");
+}
+
+int main(void)
+{
+    
+/*    printf("---------------------------------------\n");
+    printf("---------------------------------------\n");
+    printf("--- FAHRENHEIT TO CELSIUS CONVERTER ---\n");
+    printf("---------------------------------------\n");
+    printf("---      to exit press Ctrl+D      ----\n");
+    printf("---------------------------------------\n");
+    printf("---------------------------------------\n");
+*/
+    title();
+    dato_t i;
+    float res;
+    printf(">> ");
+    while(fgets(s, 10, stdin) != NULL) {
+        i = atoi(s);
+        res = ftoc(i);
+        printf("%.0f°F = %.2f°C\n", i, res);
+        printf(">> ");
+    }
+    return 0;
+}
+
+
+