c-first-steps

a C playground
Index Commits Files Refs README
   1 /*    Ejercicio 4 - Guia 2, Algoritmos y Programacion I - FIUBA    */
   2 
   3 
   4 #include <stdio.h>
   5 #include <stdlib.h>
   6 
   7 typedef enum {
   8     CELSIUS,
   9     FAHRENHEIT
  10 } escala_t;
  11 
  12 typedef float dato_t;
  13 
  14 char s[10];
  15 
  16 float ftoc(float fahrenheit) {
  17     return (((fahrenheit - 32)*5)/9);
  18 }
  19 
  20 void title()
  21 {
  22     printf("---------------------------------------\n");
  23     printf("---------------------------------------\n");
  24     printf("--- FAHRENHEIT TO CELSIUS CONVERTER ---\n");
  25     printf("---------------------------------------\n");
  26     printf("---      to exit press Ctrl+D      ----\n");
  27     printf("---------------------------------------\n");
  28     printf("---------------------------------------\n");
  29 }
  30 
  31 int main(void)
  32 {
  33     title();
  34     dato_t i;
  35     float res;
  36     printf(">> ");
  37     while(fgets(s, 10, stdin) != NULL) {
  38         i = atoi(s);
  39         res = ftoc(i);
  40         printf("%.0f°F = %.2f°C\n", i, res);
  41         printf(">> ");
  42     }
  43     return 0;
  44 }
  45 
  46 
  47