Advertisement
michael_xgrind

Peso ideal

Sep 22nd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "math.h"
  4.  
  5. int main(){
  6.     float alt, peso, ideal;
  7.     char *frase, sexo, resp;
  8.     frase = malloc(50 * sizeof (char));
  9.  
  10.     printf("Programa para calcular IMC, peso ideal e quantidade de nutrientes por dia.\n");
  11.  
  12.     do {
  13.         printf("Deseja continuar? (S/N) ");
  14.         scanf(" %c", &resp);
  15.  
  16.         if ((resp == 's') || (resp == 'S')) {
  17.  
  18.             printf("\nEntre com a sua altura: ");
  19.             scanf("%f", &alt);
  20.             printf("Entre com o seu peso: ");
  21.             scanf("%f", &peso);
  22.  
  23.             float imc = peso/pow(alt,2);
  24.  
  25.             /* condicao */
  26.             if (imc < 17) {
  27.                 frase = "Muito abaixo do peso";
  28.             } else {
  29.                 if ((imc >= 17) && (imc <= 18.49)) {
  30.                     frase = "Abaixo do peso";
  31.                 } else {
  32.                     if ((imc >= 18.5) && (imc <= 24.99)) {
  33.                         frase = "Peso normal";
  34.                     } else {
  35.                         if ((imc >= 25) && (imc <= 29.99)) {
  36.                             frase = "Acima do peso";
  37.                         } else {
  38.                             if ((imc >= 30) && (imc <= 34.99)) {
  39.                                 frase = "Obesidade I";
  40.                             } else {
  41.                                 if ((imc >= 35) && (imc <= 39.99)) {
  42.                                     frase = "Obesidade II (severa)";
  43.                                 } else {
  44.                                     frase = "Obesidade III (morbida)";
  45.                                 }
  46.                             }
  47.                         }
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             /* Saida */
  53.             printf("\nIMC: %2.2f - %s\n\n", imc, frase);
  54.             alt *= 100;
  55.             printf("Peso ideal:\nHomens: %2.2fKg\nMulheres: %2.2fKg\n\n", (alt-100)-(alt-150) / 4, (alt-100)-(alt-150) / 2);
  56.             printf("Quantidade por dia:\n");
  57.             printf("Proteina: %2.2fgr\n", 2 * peso);
  58.             printf("Agua: %2.2f litros\n", 0.035 * peso);
  59.             printf("Carboidrato: %2.2fgr a %2.2fgr\n\n", 5 * peso, 6 * peso);
  60.  
  61.             }
  62.             else {
  63.                 if ((resp == 'n') | (resp == 'N'))
  64.                     break;
  65.                 else
  66.                     printf("\nOpcao invalida!\n");
  67.             }
  68.  
  69.         } while ((resp == 'S') || (resp == 's'));
  70.  
  71.     #ifdef __WIN32__
  72.     system("pause");
  73.     #endif // __WIN32__
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement