Skip to content

Instantly share code, notes, and snippets.

@nitrix
Created September 12, 2012 01:40
Show Gist options
  • Save nitrix/3703614 to your computer and use it in GitHub Desktop.
Save nitrix/3703614 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
using namespace std;
//This function needs floating point promotion to have a working division
//This way we don't lose precision in the division.
double getBMI(double h, double w, double s)
{
return (w / (h*h)) * s;
}
//Output the BMI of the person
void output(double b)
{
cout << setprecision(2) << fixed << "Your BMI is " << b << endl << endl;
}
//Our main program
int main()
{
int height1, height2, weight1, weight2;
double bmi1, bmi2;
double scalar = 703.0;
//First person
cout << "Person 1 height: ";
cin >> height1;
cout << "Person 1 weight: ";
cin >> weight1;
bmi1 = getBMI(height1, weight1, scalar);
output(bmi1);
//Second person
cout << "Person 2 height: ";
cin >> height2;
cout << "Person 2 weight: ";
cin >> weight2;
bmi2 = getBMI(height2, weight2, scalar);
output(bmi2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment