Help with simple BMI calc

Hello, I am very new to c++ i started a couple days ago, today I tried to make a BMI calculator and cannot get the formula to work. The Calculator is text base.


any help would be very much appreciated.


Source Code::

#include <iostream>
using namespace std;

int BMI(int W, int H, int iH)
{
cout << "\n\nBMI() recieved your weight and height " << endl;
cout << "Calculating your BMI ......\n";
return (W * 703 / H * H * iH * iH);
}


int main()
{
cout << "BMI Calculator version 1. // By Nathan Greenberg\n\n";
unsigned short int weight, height, iHeight, tBMI;
cout << "Enter your Weight: ";
cin >> weight;
cout << "Enter your Height(feet): ";
cin >> height;
cout << "Enter your Height(inches): ";
cin >> iHeight;
tBMI= BMI(weight, height, iHeight);
cout << "Your BMI is " << tBMI;
cout << "\n\n\n\nThank you for using :::NG Software:::";
char response;
cin >> response;
return 0;
}
Last edited on
your formula for BMI is wrong. it is like so:

(weight * 703) / height (in inches)

what you want to do is multiply the height they enter in feet by 12 and add it to iHeight. make your function body more like this:

1
2
3
4
5
6
7
8
9
10

double BMI(double W, double H, double iH)
{
	cout << "\n\nBMI() recieved your weight and height " << endl;
	cout << "Calculating your BMI ......\n";
	
	iH += H * 12;

	return (W * 703) / (iH * iH);
}


lastly BMI's are rarely whole numbers so i would change all the variables in your program to type double. i did this for the function, and you should do the same in main.

should be hunky dory like this :)
Last edited on
H*H*iH*iH doesn't get the height in inches. Multiply the height by twelve and add inches to that. Try:

1
2
3
4
5
6
7
int BMI(int W, int H, int iH)
{
cout << "\n\nBMI() recieved your weight and height " << endl;
cout << "Calculating your BMI ......\n";
iH += H*12;
return ((W*703) / (iH*iH));
}


BTW, unsigned short int is unnecessary; just use unsigned (in the BMI() args as well).

EDIT: Whoa...@ascii posted just before me.
Last edited on
haha great minds think alike :)
Thanks for the Help! im very new to c++ but one question why is short unecessary in unsigned short int? thanks!
theres no need for the variable to be short. once again, i reccommended changing everything to type double because BMI's are almost always decimal values, so you want to more precision by making your variables doubles.
Topic archived. No new replies allowed.