Ideal Weight Exercise (Language C)

Asked

Viewed 123 times

0

Would anyone like to explain to me how I could be part of the "situation" in this exercise? how would I represent this in the algorithm? just need to finish, the rest works.. Exercicio

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

char sexo, sair;
float peso, altura, diferenca, pi, situacao1, situacao2;

main()

{
    do{
        printf("Digite o seu sexo, M para masculino ou F para feminino: ");
        scanf(" %c", &sexo);


        printf("Digite a sua altura(METROS): ");
        scanf("%f", &altura);


        printf("Digite o seu peso(KG): ");
        scanf("%f", &peso);

        if(sexo == 'M'){
            pi = (72.7*altura)-58;
            diferenca = peso - pi;
            printf("O seu peso ideal e: %0.2f\n", pi);
            printf("Diferenca de peso: %0.2f\n", diferenca);

        }else if(sexo == 'F'){
            pi = (62.1*altura)-44.7;
            diferenca = peso - pi;
            printf("O seu peso ideal e: %0.2f\n", pi);
            printf("Diferenca de peso: %0.2f\n", diferenca);

        }                                 

        situacao1 = (pi*0.05)+pi;  //eu pensei em fazer isso e dps adicionar IF
        situacao2 = pi-(pi*0.05);  //mas nao deu certo..


        printf("Sair [S/N]:");
        scanf(" %c", &sair);
        system("cls");
        if((sair == 'S')||(sair == 's')) break;

    }while(1);


        return 0;
}

  • What exactly didn’t work out? Are you calculating the thresholds for fat on situacao1 and lean in situacao2. You have his current weight in the variable peso then all that’s left is the comparisons... E.g., if (peso >= situacao1)...

1 answer

3


Just direct test and print the message.

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

char sexo, sair;
float peso, altura, diferenca, pi, situacao1, situacao2;

main()

{
    do{
        printf("Digite o seu sexo, M para masculino ou F para feminino: ");
        scanf(" %c", &sexo);


        printf("Digite a sua altura(METROS): ");
        scanf(" %f", &altura);


        printf("Digite o seu peso(KG): ");
        scanf(" %f", &peso);

        if(sexo == 'M'){
            pi = (72.7*altura)-58;
            diferenca = peso - pi;
            printf("O seu peso ideal e: %0.2f\n", pi);
            printf("Diferenca de peso: %0.2f\n", diferenca);

        }else if(sexo == 'F'){
            pi = (62.1*altura)-44.7;
            diferenca = peso - pi;
            printf("O seu peso ideal e: %0.2f\n", pi);
            printf("Diferenca de peso: %0.2f\n", diferenca);

        }                                

        if (peso > pi * 1.05)
            printf("Gordo\n");
        else
            if (peso < pi * 0.95)
                printf("Magro\n");
            else
                printf("Ideal\n");

        printf("Sair [S/N]:");
        scanf(" %c", &sair);
        system("cls");
        if((sair == 'S')||(sair == 's')) break;

    }while(1);


        return 0;
}
  • pq you put there in if 1.05 and the other 0.95? pq would be these numbers?

  • 1

    Mathematically: pi * 1.05 is the same as pi + pi*0.05, i.e.: pi * ( 1 + 0.05), and pi * 0.95 is the same as pi - pi*0.05, that is: pi * (1 - 0.05), that is pi + 5% and pi - 5%.

  • can you answer my question? https://answall.com/questions/469237/identificar-registrations-sequentialof each user

Browser other questions tagged

You are not signed in. Login or sign up in order to post.