Body Fate By Using Switch Statement

Convert This Code to Switch Statement...
#include <iostream>
#include <math.h>
using namespace std;
void main()
{
char gender;
float a1, a2, a3, a4, a5,bw,wsm,wrm,hm,frm;

cout << "Are you a man or a woman? \n Enter M for Man & F for Woman";
cin >> gender;
while (gender != 'm' && 'M' && 'f' && 'F')
{
cout << "You have entered an invalid input \n Enter M for Man & F for Woman" << endl;
cin >> gender;
}

if (gender == 'm' || 'M')
{
cout << "Enter the Body Weight ";
cin >> bw;
cout << "Enter the Waist Measurement ";
cin >> wsm;
cout << "Enter the Wrist Measurement ";
cin >> wrm;
cout << "Enter the Hip Measurement ";
cin >> hm;
a1 = (bw*1.082) + 94.42;
a2 = wrm*4.15;

cout << "Your Body Fat is " << ((bw - (a1 - a2)) * 100) / bw<<endl;

}
else

{
cout << "Enter the Body Weight ";
cin >> bw;
cout << "Enter the Waist Measurement ";
cin >> wsm;
cout << "Enter the Wrist Measurement ";
cin >> wrm;
cout << "Enter the Hip Measurement ";
cin >> hm;
cout << "Enter the Fore arm Measurement ";
cin >> hm;

a1 = (bw * 0.732);
a2 = wrm * 3.140;
a3 = wsm * 0.157;
a4 = hm * 0.249;
a5 = frm * 0.434;

cout << "Your Body Fat is " << ((bw - (a1 + a2 - a3 - a4 + a5)) * 100) / bw<<endl;

}

system("pause");
}
Ok...
1
2
3
4
5
switch( gender )
{
// good luck
default: break;
}
Last edited on
switch(gender)
{
case'm':
case'M':
//your calculations you can just copy paste

break ;

case 'f':
case 'F':
// your calculations you can just copy paste

break ;

default: break;
}
Last edited on
Topic archived. No new replies allowed.