Body mass index - C

2

Write a program in C, which:

Calcule el Indice de Masa Corporal de un individuo, solicitando su peso y su estatura.
Si el IMC es menor a 20 indique "Peligro, estas bajo de peso"
Si el IMC esta entre 20 y 25 indique "Felicidades estas en tu peso"
Si el IMC esta entre 25 y 30 (sin incluir a 30) indique "Tienes sobrepeso"
Si el IMC esta entre 30 y 35 (sin incluir a 35) indique "tienes obesidad"
Si el IMC es mayor o igual a 35 indique "Tienes obesidad morbida"
Repita el proceso tantas veces como el usuario lo desee
Al final indique cuantas personas se encontraron en cada rango de peso

Note:

Permita unicamente la captura de pesos y estaturas mayores a 0

I just need to allow me to capture weights and statures greater than 0 and repeat the process as many times as the user wants and at the end indicate how many people were in each weight range

/* Programa para hallar el índice de masa corporal */

#include <stdlib.h>
#include <stdio.h>



int main()
{
 float altura, peso, IMC;

    printf("Introduce tu altura (en metros): ");
    scanf("%f", & altura);

    printf("Introduce tu peso (en kilogramos): ");
    scanf("%f", & peso);

    IMC = peso/(altura*altura);

    printf("Tu indice de masa corporal es: ", IMC );

    if (IMC<20)
        printf("Peligro, estas bajo de peso");
        else
     if (20<IMC&&IMC<=25)
        printf("Felicidades estas en tu peso");
        else
     if (25<IMC&&IMC<30)
        printf("Tienes sobrepeso"); 
        else
     if (30<IMC&&IMC<35)
        printf("tienes obesidad"); 
        else
     if (35<=IMC)
        printf("Tienes obesidad morbida"); 


return 0;

}
    
asked by Luis Felipe Grijalva 25.03.2017 в 19:40
source

1 answer

1
do {
  printf("Introduce tu altura (en metros): ");
  scanf("%f", & altura);
while( f == 0.0f );

do {
  printf("Introduce tu peso (en kilogramos): ");
  scanf("%f", & peso);
while( f == 0.0f );

With that, repeat the questions until you enter values other than 0.

To count the people in each range, you have to use 5 extra variables:

int bajo = 0,
    ideal = 0,
    sobrepeso = 0,
    obesidad = 0,
    morbida = 0;

and change your if( ) ... else :

if( IMC < 20 ) {
    printf("Peligro, estas bajo de peso");
    ++ bajo; 
} else if( 20 < IMC && IMC <= 25 ) {
    printf("Felicidades estas en tu peso");
    ++ ideal;
} else if( 25 < IMC && IMC < 30 ) {
...

To support multiple people, you must use a loop, similar to the one used to request the data. You wrap it all, from the declaration of variables. You will also need another extra variable:

float altura ...;
int bajo, ...;
int loop; // <-- Otra variable mas.

do {

   // Todo lo que tienes hasta ahora, con los cambios que te he indicado.

  // Y añadimos esto al final.
  printf( "Introduzca 0 para salir; otro para añadir mas personas.\n" );
  scanf( "%d", &loop );
} while( &loop );

return 0;

No I've tried it, but, except for minimal changes, it should work. Post a comment if there is an error.

    
answered by 25.03.2017 в 20:06