BMI Calculator Project In C Programming Beginner to Advance Level || BMI in C Programming Tutorial
This is the BMI Calculator Project In C Programming for Beginners to Advance Level || BMI in C Programming Tutorial . This BMI Calculator is coded in C Programming using switch case, If else and other many unit conversions methods , operators in C Programming. BMI is a value derived from the mass and height of a person. The BMI is defined as the body mass divided by the square of the body height, and is expressed in units of kg/m², resulting from mass in kilograms and height in meter. This is perfect tutorial for BMI Calculator in C Programming.
Source code :
// THIS IS CODE FOR BMI CALCULATOR
#include<stdio.h>
int main(){
float w,h,bmi,ow;
int choice,repeat;
printf("enter your weight in kg : ");
scanf("%f",&w);
printf("for height in meter press 1 : ft and inch press 2 : cm press 3 : ");
scanf("%d",&choice);
switch (choice)
{
float a,b;
case 1:
printf("enter the height in meter : ");
scanf("%f",&h);
break;
case 2:
printf("enter your height ft value : ");
scanf("%f",&a);
printf("enter your height inch value : ");
scanf("%f",&b);
a = a*12; // inch
b = b+a;
h= 0.0254 * b; // height in meters converted
break;
case 3:
printf("enter your heigth in cm : ");
scanf("%f",&a);
h = 0.01*a;
break;
default:
printf("please choose valid option ");
break;
}
bmi = w/(h*h);
printf("your BMI is %.2f ",bmi);
if(bmi<18.5){
bmi = 18.5 - bmi ;
ow = bmi * h*h;
printf("you are underweight .\n you have to increase your weigth %.2f",ow);
}
else if (bmi>24.9){
bmi = bmi - 24.9;
ow = bmi *h*h;
printf("you are overweight .\n you have to decrease your weigth %.2f",ow);
}
else
printf("you are a healthy person");
do{
printf("\n\nfor replay press 1 : for end press 2 : ");
scanf("%d",&repeat);
if(repeat == 1){
printf("enter your weight in kg : ");
scanf("%f",&w);
printf("for height in meter press 1 : ft and inch press 2 : cm press 3 : ");
scanf("%d",&choice);
switch (choice)
{
float a,b;
case 1:
printf("enter the height in meter : ");
scanf("%f",&h);
break;
case 2:
printf("enter your height ft value : ");
scanf("%f",&a);
printf("enter your height inch value : ");
scanf("%f",&b);
a = a*12; // inch
b = b+a;
h= 0.0254 * b; // height in meters converted
break;
case 3:
printf("enter your heigth in cm : ");
scanf("%f",&a);
h = 0.01*a;
break;
default:
printf("please choose valid option ");
break;
}
bmi = w/(h*h);
printf("your BMI is %.2f ",bmi);
if(bmi<18.5){
bmi = 18.5 - bmi ;
ow = bmi * h*h;
printf("you are underweight .\n you have to increase your weigth %.2f",ow);
}
else if (bmi>24.9){
bmi = bmi - 24.9;
ow = bmi *h*h;
printf("you are overweight .\n you have to decrease your weigth %.2f",ow);
}
else
printf("you are a healthy person");
}
}while(repeat == 1 || repeat !=2);
return 0;
}
ConversionConversion EmoticonEmoticon