The code is meant to take a program description (in comments) and convert that to code. Mainly uses boundary checks and conditions and input/output
- If statement order matters --> Try for yourself and change the ordering of the if statement
- The & in front of the variable means that we are passing an address. This is needed for scanf.
/*
* File: main.c
* Author: user
*
* Created on September 21, 2015, 9:11 AM
*/
#include <stdio.h>
#include <stdlib.h>
/*
* Build a program that computes a person's Body Mass Index. BMI is computed as
* BMI = Person's Weight (KG)/ Person's Height (m) ^2 and tell if a person is
* overweight.Overweight BMI is 25.
*
*/
int main(int argc, char** argv) {
// Get user's height and weight
double height, weight, BMI;
printf("Please enter the height(m): ");
scanf("%lf", &height);
printf("Please enter the weight(kg): ");
scanf("%lf", &weight);
// Compute the BMI: BMI = w/h^2
BMI = weight / (height * height);
// Output BMI
printf("Your BMI \tis: %20.4lf\n", BMI);
// Tell if the user is overweight or not
if (BMI >= 40) {
printf("See a doctor?\n");
} else if (BMI >= 25) {
printf("Overweight\n");
} else {
printf("Normal\n");
}
return (EXIT_SUCCESS);
}