Skip to content

Commit

Permalink
Add BMI Calculator code
Browse files Browse the repository at this point in the history
  • Loading branch information
junian committed Feb 6, 2019
1 parent 5a586fd commit 67abee3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bmi-calculator/README.md
@@ -0,0 +1,3 @@
# Body Mass Index (BMI) Calculator

Determine wether you're Underweight, Normal weight, Overweight, Obesity, or Over Obesity based on your body mass index, which is calculated by using weight and height.
52 changes: 52 additions & 0 deletions bmi-calculator/bmi-calculator.cpp
@@ -0,0 +1,52 @@
/*###################################################
# #
# Body Mass Index (BMI) Calculator #
# Copyright (c) 2008 - 2018 Junian Triajianto #
# #
###################################################*/

#include <cstdio>
#include <cstdlib>

char toUpper(char x);

int main() {
char r;
do {
float TB, IMT;
int BB;
printf("Body Mass Index (BMI) Calculator\n");
printf("================================\n\n");
printf("BW : Weight (kg)\n");
printf("BH : Height (m)\n");
printf("BMI : Body Mass Index\n\n");
printf("BW : ");
scanf("%d", & BB);
printf("BH : ");
scanf("%f", & TB);
IMT = BB / (TB * TB);
printf("BMI : %0.2f\n\n", IMT);
printf("You are ");
if (IMT < 18.5)
printf("Underweight");
else if (IMT < 23)
printf("Normal weight");
else if (IMT < 25)
printf("Overweight");
else if (IMT < 30)
printf("Obesity");
else
printf("Over Obesity");
printf("\n\nTry again [Y/N]? ");
do {
r = getchar();
r = toUpper(r);
} while (r != 'Y' && r != 'N');
} while (r == 'Y');
return 0;
}

char toUpper(char x) {
if (x >= 97 && x <= 122) x = x - 32;
return x;
}

1 comment on commit 67abee3

@DemeSKVR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing!!

Please sign in to comment.