• Language

    C

  • Description

    Create an Ideal Weight application that accepts input for:
    - A person's name
    - A person's height
    -The system of measurement they wish to use (metric or imperial).
    The program will use the person's height to calculate his/her ideal healthy weight using a formula produced from the formula for body mass index (BMI). The BMI is a statistical measurement which compares a person's weight and height.
    Though it does not actually measure the percentage of body fat, it is a useful tool to estimate a healthy body weight based on a person s height. According to the BMI, a value of 18.5 to 25 is considered healthy.
    In this program, allow the user to use either the imperial measurements or metric to calculate a healthy weight.
    Metric: Weight (kg) = height (metres) × height (metres) × 25
    Imperial: Weight (pounds) = height (inches) × height (inches) × 25 ÷ 703

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int system_of_measurement;
    float healthy_weight, height;
    char person_name[63];
    printf ("Enter the person name: ");
    scanf ("%[^\r\n]", person_name);
    (void) getchar ();
    printf ("Enter the value of height: ");
    scanf ("%f", &height);
    (void) getchar ();
    printf ("Select the value of system of measurement.\n");
    printf ("\t1.- metric\n");
    printf ("\t2.- imperial\n");
    printf ("\t: ");
    do {
        scanf ("%d", &system_of_measurement);
        (void) getchar ();
        if (system_of_measurement<1||system_of_measurement>2)
            printf ("Wrong value. Please, enter it again.: ");
    } while (system_of_measurement<1||system_of_measurement>2);
    if(system_of_measurement==1)
    {
        printf ("kg\n");
        healthy_weight=height*height*25;
    }
    else
    {
        printf ("pounds\n");
        healthy_weight=height*height*25/703;
    }
    if(healthy_weight>25)
        printf ("You have to lose weight.\n");
    if(healthy_weight>=18.5&&healthy_weight<=25)
        printf ("Your weight is considered healthy.\n");
    if(healthy_weight<18.5)
        printf ("You have to win weight.\n");
    printf ("Person name: %s\n", person_name);
    printf ("Value of healthy weight: %g\n", healthy_weight);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}