C++ code to calculate body fat of a person (Logic explained)

Here is the C++ code to calculate body fat of a person  . It works by inputting some necessary data of person. You all should have in mind how it works exactly. Here is the algorithm.

  Steps
User side
1: User asked for his/her gender
2: User asked to enter body-weight 
3: User asked to enter wrist measurement 
4: User asked to enter waist measurement
5: User asked to enter hip measurement
6: User asked to enter forearm measurement
7: User displayed body fat
8: User displayed body fat percentage
9: Program ends here
Developer side
1: Declare variables that are going to be used in program .
2: Input gender from user (because there are different formulas for different genders)
3: If User is woman follow this
 Input enter body-weight (Calculate  A1=(bodyweight*0.732)+8.987;)
 Input wrist measurement (Calculate  A2=(wrist)/3.140;
 Input waist measurement (Calculate   A3=(waist)*0.157;)
 Input  hip measurement (Calculate   A4=(hip)*0.249;)
 Input  forearm measurement (Calculate   A5=(forearm)*0.434;)
  Know calculate following :  B=A1+A2-A3-A4+A5;
                         bodyfat=bodyweight-B;
                     
4:  If user is man then follow this
    Input body-weight (Calculate  A1=(bodyweight*1.082)+94.42;)
    Input wrist measurement (Calculate A2=(wrist)*4.15;)
    Know calculate following 
                            B=A1-A2;
                           bodyfat=bodyweight-B;
5: Calculate percentage body fat (To calculate percentage body fat use this formula  bodyfatparcentage=(bodyfat*100)/bodyweight;)

5: Output results 
6: Program ends here.
Here is the C++ code.

Code:

#include<iostream>

using namespace std;
void main()
{      char gender;
       float bodyweight,wrist,waist,hip,forearm;
       float A1,A2,A3,A4,A5,B,bodyfat,bodyfatparcentage;
       cout<<"\t\tThis program is to calculate the body fat of a person"<<endl;
       cout<<"If you are woman than press \'w\' . If you are man than press \'m\'  "<<endl;
       cin>>gender;
       switch(gender)
       {
                     case 'w':
             
                     cout<<"Enter your body weight ";
                     cin>>bodyweight;
                     A1=(bodyweight*0.732)+8.987;
                     cout<<"Enter your wrist measurement ";
                     cin>>wrist;
                     A2=(wrist)/3.140;
                     cout<<"Enter your waist measurement ";
                     cin>>waist;
                     A3=(waist)*0.157;
                     cout<<"Enter your hip measurement ";
                     cin>>hip;
                     A4=(hip)*0.249;
                     cout<<"Enter your forearm measurement ";
                     cin>>forearm;
                     A5=(forearm)*0.434;
                     //calculting B
                     B=A1+A2-A3-A4+A5;
                     bodyfat=bodyweight-B;
                     cout<<"Body Fat is equal to = "<<bodyfat<<endl;
                     bodyfatparcentage=(bodyfat*100)/bodyweight;
                     cout<<"Body Fat percentage is equal to = "<<bodyfatparcentage<<"%"<<endl;
             
              break;
       case 'm':
                    
                           cout<<"Enter your body weight ";
                           cin>>bodyweight;
                           A1=(bodyweight*1.082)+94.42;
                           cout<<"Enter your wrist measurement ";
                           cin>>wrist;
                           A2=(wrist)*4.15;
                           B=A1-A2;
                           bodyfat=bodyweight-B;
                           cout<<"Body Fat is equal to = "<<bodyfat<<endl;
                           bodyfatparcentage=(bodyfat*100)/bodyweight;
                            cout<<"Body Fat percentage is equal to = "<<bodyfatparcentage<<"%"<<endl;
                     break;
       default:
        cout<<"wrong input"<<endl;
       }
       system("pause");
}



Output:



Comments

  1. is it possibl e using while loop

    ReplyDelete
  2. Thanks for sharing

    Village Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
    As a best video production company in Bangalore, we produce quality and creative videos to our clients.

    ReplyDelete
  3. Thank you for sharing.

    ReplyDelete

Post a Comment