Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Conversor de Temperaturas
  3. * Feito Por: Diego Charles
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. int main () {
  10.  
  11.     inicio:
  12.              
  13.     system("clear");
  14.    
  15.     printf("\n |-------------------------------------|");
  16.     printf("\n | Conversor de Temperaturas           |");
  17.     printf("\n |-------------------------------------|");
  18.      
  19.     printf("\n\n  Que Tipo de Conversao Voce Deseja Fazer?\n");
  20.     printf("\n   (1) Celsius Para Farenheit   (4) Farenheit Para Celsius");
  21.     printf("\n   (2) Celsius Para Kelvin      (5) Kelvin Para Celsius");
  22.     printf("\n   (3) Farenheit Para Kelvin    (6) Kelvin Para Farenheit");
  23.  
  24.     int operacao;
  25.     printf("\n\n  Digite o Valor da Operacao: ");
  26.     scanf("%d", &operacao);
  27.  
  28.     float celsius,faren,kelvin;
  29.  
  30.     switch (operacao){
  31.        
  32.     /* (1) CELSIUS > FARENHEINT */
  33.    
  34.     case 1 :
  35.     printf("\n\n  Digite o Valor em Celsius: ");
  36.     scanf("%f", &celsius);
  37.  
  38.      if (celsius < (-273.15)) {
  39.        printf("\n  Valor Incorreto!");
  40.        printf("\n  O Menor Valor medido em Celsius eh: -273");
  41.        printf("\n\n  Digite um valor correto em Celsius: ");
  42.        scanf("%f", &celsius);
  43.     }
  44.  
  45.      else {
  46.          printf("\n\n   Resolvendo: F = (%.2f * 1.8) + 32", celsius);
  47.          faren = (celsius * 1.8) + 32;
  48.          printf("\n\n   Resultado: ");
  49.          printf(" (%.2f)ºC = (%.2f)ºF \n\n", celsius,faren);
  50.     }
  51.    
  52.     break;
  53.    
  54.     /* (2) CELSIUS > KELVIN */
  55.    
  56.     case 2 :
  57.     printf("\n\n  Digite o Valor em Celsius: ");
  58.     scanf("%f", &celsius);
  59.  
  60.      if (celsius < 0) {
  61.        printf("\n  Valor Incorreto!");
  62.        printf("\n  O Menor Valor medido em Celsius eh: -273");
  63.        printf("\n\n  Digite um valor correto em Celsius: ");
  64.        scanf("%f", &celsius);
  65.     }
  66.  
  67.      else {
  68.          printf("\n\n   Resolvendo: K = %.2f + 273", celsius);
  69.          kelvin = celsius + 273;
  70.          printf("\n\n   Resultado: ");
  71.          printf("(%.2f)ºC = (%.2f)K \n\n", celsius,kelvin);
  72.     }
  73.    
  74.     break;
  75.    
  76.     /* (3) FARENHEINT > KELVIN */
  77.    
  78.     case 3 :
  79.     printf("\n\n  Digite o Valor em Farenheit: ");
  80.     scanf("%f", &faren);
  81.  
  82.      if (faren < (-273.15)) {
  83.        printf("\n  Valor Incorreto!");
  84.        printf("\n  O Menor Valor medido em Farenheit eh: X");
  85.        printf("\n\n  Digite um valor correto em Farenheit: ");
  86.        scanf("%f", &faren);
  87.     }
  88.  
  89.      else {
  90.          printf("\n\n   Resolvendo: K = (%.2f + 459,27) * (5/9)", faren);
  91.          kelvin = (faren + 459,27) * (5/9);
  92.          printf("\n\n   Resultado: ");
  93.          printf(" (%.2f)ºF = (%.2f)K \n\n", faren,kelvin);
  94.     }
  95.    
  96.     break;
  97.    
  98.     /* (4) FARENHEINT > CELSIUS */
  99.    
  100.     case 4 :
  101.     printf("\n\n  Digite o Valor em Farenheit: ");
  102.     scanf("%f", &faren);
  103.  
  104.      if (faren < (-273.15)) {
  105.        printf("\n  Valor Incorreto!");
  106.        printf("\n  O Menor Valor medido em Farenheit eh: X");
  107.        printf("\n\n  Digite um valor correto em Farenheit: ");
  108.        scanf("%f", &faren);
  109.     }
  110.  
  111.      else {
  112.          printf("\n\n   Resolvendo: C = (5/9) * (%.2f - 32)", faren);
  113.          celsius = (5/9) * (faren - 32);
  114.          printf("\n\n   Resultado: ");
  115.          printf(" (%.2f)ºF = (%.2f)ºC \n\n", faren,celsius);
  116.     }
  117.  
  118.     break;
  119.    
  120.     /* (5) KELVIN > CELSIUS */
  121.    
  122.     case 5 :
  123.     printf("\n\n  Digite o Valor em Kelvin: ");
  124.     scanf("%f", &kelvin);
  125.  
  126.      if (kelvin < 0) {
  127.        printf("\n  Valor Incorreto!");
  128.        printf("\n  O Menor Valor Medido em Kelvin Eh: 0 (Zero Absoluto)");
  129.        printf("\n\n  Digite um valor correto em Kelvin: ");
  130.        scanf("%f", &kelvin);
  131.     }
  132.  
  133.      else {
  134.          printf("\n\n   Resolvendo: C = %.2f - 273", kelvin);
  135.          celsius = kelvin - 273;
  136.          printf("\n\n   Resultado: ");
  137.          printf(" (%.2f)K = (%.2f)ºC \n\n", kelvin,celsius);
  138.     }
  139.  
  140.     break;
  141.    
  142.     /* (6) KELVIN > FARENHEIT */
  143.    
  144.     case 6 :  
  145.     printf("\n\n  Digite o Valor em Kelvin: ");
  146.     scanf("%f", &kelvin);
  147.  
  148.      if (kelvin < 0) {
  149.        printf("\n  Valor Incorreto!");
  150.        printf("\n  O Menor Valor Medido em Kelvin Eh: 0 (Zero Absoluto)");
  151.        printf("\n\n  Digite um valor correto em Kelvin: ");
  152.        scanf("%f", &kelvin);
  153.     }
  154.  
  155.      else {
  156.          printf("\n\n   Resolvendo: F = (%.2f * (9/5)) - 459.67 ", kelvin);
  157.          faren = (kelvin * (9/5)) - 459.67;
  158.          printf("\n\n   Resultado: ");
  159.          printf(" (%.2f)K = (%.2f)ºF \n\n", kelvin,faren);
  160.     }
  161.    
  162.     break;
  163.  
  164.     /* Informa erro se o dado inserido for diferente das opçoes */
  165.     default : printf("\n\n ERRO - Operacao Invalida!");
  166.        
  167.     }
  168.    
  169.     /* Voltar ao Inicio */
  170.    
  171.     int repetir;
  172.     printf("\n\n Deseja Executar Outra Operacao? (s/n): ");
  173.     scanf("%d", &repetir);
  174.     if (repetir = 's') { goto inicio; }
  175.     else { return 0; }
  176.    
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement