codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> using namespace std; // the main function has 2 parameters! // some compilers might complain if you omit them int main(int, char**) { cout << "weight (in KG): "; double weight; cin >> weight; cout << "height (in meters): "; double height; cin >> height; // since you compare a double to a constant, i'd take a double // constant (0.0 instead of 0), but that's almost purely cosmetic if ((weight <= 0.0) || (height <= 0.0)) { // you can use \n instead of endl, saves you some << cout << "invalid input\n"; } else { double bmi = (weight / (height * height)); cout << "Your Body Mass Index is " << bmi << ".\n"; // check your code with bmi 20.0 ;) if ((bmi > 0.0) && (bmi <= 20.0)) { cout << "You are within the healthy BMI range. Congratulations!\n"; } else if ((bmi > 20.0) && (bmi <= 25.0)) { cout << "You are within the healthy BMI range. Congratulations!\n"; } else { cout << "You have exceeded the healthy BMI range.\n"; } } return 0; }
Private
[
?
]
Run code
Submit