# BMI Metric and Imperial Calculator problems...

• 12-30-2010
TBsparky
BMI Metric and Imperial Calculator problems...
Hey everyone, i seem to be having a little bit of a problem with my coding for converting CM into inches, i get the answer no problem, but i then need to times the answer by itself to get the correct value but i'm unsure how to do so, here is my code.
Code:

```/* * File: main.cpp * Author: 20524455 * * Created on 01 December 2010, 08:59 */ #include <cstdlib> #include <iostream> #include <math.h> using namespace std; char gender; char height; int while_cnt = 0; char option1 ='y'; int femcnt; int malecnt; int J=2.54; int underweight; int normalweight; int overweight; int obese; int underweightf; int normalweightf; int overweightf; int obesef; double Imperial; double Metric; char weight; double Imperial2; double Metric2; double choice1; double choice2; double BMI1; int I = 703; int main() { cout<<"Created and Designed by Rhys Thomas, 2010-2011"<<endl; cout<<"Male/Female: Body Mass Index Calculator"<<endl; cout<<"In both Metric and Imperial Calculations"<<endl<<endl<<endl; while (option1 == 'y') { cout<<"Please specify your Gender: (M/F)"<<endl; cin>>gender; if ((gender =='M')||(gender =='m') ) { cout<<" "<<endl<<endl; cout<<"You have chosen Male"<<endl<<endl; malecnt = malecnt +1; } else if ((gender =='F')||(gender =='f') ) { cout<<" "<<endl<<endl; cout<<"You have chosen Female"<<endl<<endl; femcnt= femcnt +1; } cout<<"Would you like your Height in Inches or Meteres? (I/M)"<<endl; cin>>height; cout<<" "<<endl<<endl; if ((height =='I')||(height =='i') ) { cout<<"Please enter your Height in Inches: "<<endl; cin>>Imperial; Imperial= Imperial * Imperial; choice1=Imperial; cout<<" "<<endl<<endl; } else if ((height =='M')||(height =='m') ) { cout<<"Please enter your Height in Cetremetres: "<<endl; cin>>Metric; cout<<" "<<endl<<endl; Metric= Metric / 2.54; <<<<<<<<PROBLEM CODE choice1=Metric; cout<<choice1; } cout<<"Would you like your Weight in Pounds or KG? (P/K)"<<endl; cin>>weight; cout<<" "<<endl<<endl; if ((weight =='P')||(weight =='p') ) { cout<<"Please enter your Weight in Pounds: "<<endl; cin>>Imperial2; Imperial2= Imperial2 * I; cout<<Imperial2; choice2=Imperial2; BMI1= choice2 / choice1; cout<<BMI1; cout<<" "<<endl<<endl; cout<<"Your BMI is " <<BMI1<<endl<<endl; } else if ((weight =='K')||(weight =='k') ) { cout<<"Please enter your Weight in KG: "<<endl; cin>>Metric2; choice2=Metric2 * 2.2 * I; BMI1= choice2 /choice1; cout<<BMI1; cout<<" "<<endl<<endl; cout<<"Your BMI is " <<BMI1<<endl<<endl; } if (BMI1 <=17.5) { cout<<"You are classed within the: Under-Weight Group"<<endl<<endl; if ((gender =='M')||(gender =='m') ) { cout<<" "<<endl<<endl; underweight=underweight+1; cout<<"The current Male count for this group is :" <<underweight<<endl<<endl; } else if ((gender =='F')||(gender =='f') ) { underweightf=underweightf+1; cout<<"The current Female count for this group is :" <<underweightf<<endl<<endl; } } if (BMI1 >=18) { cout<<"You are classed within the: Normal Weight Group"<<endl<<endl; if ((gender =='M')||(gender =='m') ) { normalweight=normalweight+1; cout<<"The current Male count for this group is :" <<normalweight<<endl<<endl; } else if ((gender =='F')||(gender =='f') ) { normalweightf=normalweightf+1; cout<<"The current Female count for this group is :" <<normalweightf<<endl<<endl; } } if (BMI1 >=25) { cout<<"You are classed within the: Over-Weight Group"<<endl<<endl; if ((gender =='M')||(gender =='m') ) { overweight=overweight+1; cout<<"The current Male count for this group is :" <<overweight<<endl<<endl; } else if ((gender =='F')||(gender =='f') ) { overweightf=overweightf+1; cout<<"The current Female count for this group is :" <<overweightf<<endl<<endl; } } if (BMI1 >=30) { cout<<"You are within the: Obese Group"<<endl<<endl; if ((gender =='M')||(gender =='m') ) { obese=obese+1; cout<<"The current Male count for this group is :" <<obese<<endl<<endl; } else if ((gender =='F')||(gender =='f') ) { obesef=obesef+1; cout<<"The current Female count for this group is :" <<obesef<<endl<<endl; } } while_cnt++; cout<<"do you wish to enter another BMI ? (y/n)"<<endl<<endl; cin>>option1; } cout<<"The total of each group is as followes: "<<endl<<endl; cout<<"Males Under-Weight: "<<underweight<<endl; cout<<"Female's Under-Weight " <<underweightf<<endl; cout<<"Males Normal-Weight: "<<normalweight<<endl; cout<<"Female's Normal-Weight " <<normalweightf<<endl; cout<<"Males Over-Weight: "<<overweight<<endl; cout<<"Female's Over-Weight " <<overweightf<<endl; cout<<"Males Obese: "<<obese<<endl; cout<<"Female's Obese: " <<obesef<<endl; cout<<"The total male count is: "; cout<<malecnt<<endl; cout<<"The total female count is: "; cout<<femcnt<<endl; return 0; }```
• 12-30-2010
Salem
You could edit your post so that the code tags are around your code.
• 12-30-2010
TBsparky
I was highlighting the code that was the problem. I thought it would have been easier to see but Ok, i'll use the code tags.
• 12-30-2010
User-_-Name
Perhaps you can elaborate a bit more on your problem? I think this is the result you were looking for.

Code:

```else if ((height =='M')||(height =='m') ) { cout<<"Please enter your Height in Cetremetres: "<<endl; cin>>Metric; cout<<" "<<endl<<endl; Metric = (Metric / 2.54)*2; //PROBLEM CODE choice1 = Metric; cout << choice1 << "\n\n"; }```
• 12-30-2010
TBsparky
That coding doesn't actually work it's giving me a whole different value lol.

What i want to happen is when a user types a value e.g. 180 it will be coverted ino inches by ( / 2.54 = 70.8661) i wanted then to times 70.8661 by itself to get the correct BMI Height
• 12-30-2010
tabstop
So why not leverage what you've already done?
Code:

```Imperial = Metric / 2.54; Imperial = Imperial * Imperial;```
• 12-30-2010
TBsparky
Thank you! That worked perfectly, although I dont quite understand the coding. Does it use the Imperial * Imperial function for Inches and then the /2.54 in metres? I ask this as i will have to explain my code aswell.
• 12-30-2010
rags_to_riches
Holy global variables Batman!

Imperial is not a function...it's a variable! The only function in your completely unindented code (which is miserable to read) is main().
• 12-30-2010
tabstop
Quote:

Originally Posted by TBsparky
Thank you! That worked perfectly, although I dont quite understand the coding. Does it use the Imperial * Imperial function for Inches and then the /2.54 in metres? I ask this as i will have to explain my code aswell.

Dude, that's "your" code. I didn't write any of that. Why did you put it in the program if you don't know what it does?
• 12-30-2010
TBsparky
Thank you for the clarification lol.... anyway, being a total newbie at C++ i wasn't too sure about the coding or the structure, i prefer VB but you really know how to make a guy want to learn code, i'm gunna be writing descriptions now my coding is complete.