I am trying to get my program to restart if the user enters a y, and terminiate if the user enters n.
What am I leaving off here, or what am I typing wrong?
code:
#include <iostream>
using namespace std;
int BMICalc(int weight, int height);
int main()
{
int weight ; // weight in pounds
int height ; // height in inches
float BMI ; // Body Mass Index
bool DoItAgain ;
char Repeat ;
cout << " " << endl ;
cout << "Body Mass Index (BMI) Calculator" << endl ;
cout << " " << endl ;
while (DoItAgain = true) ;
{
cout << "Enter your weight in pounds. (please round to nearest whole number): " ;
cin >> weight ;
cout << "Enter your height in inches. (please round to nearest whole number): " ;
cin >> height ;
BMI = BMICalc(weight, height) ;
cout << "Your BMI is" << BMI << endl ;
if (BMI < 18.5)
cout << "You are underweight." << endl ;
if (BMI <= 24.9)
cout << "Congratulations, you are a healthy weight." <<endl ;
if (BMI <= 29.9)
cout << "You are over weight." << endl ;
if (BMI <= 39.9)
cout << "You are obese." << endl ;
if (BMI >= 40.0)
cout << "You are severely obese." << endl ;
cout << " " << endl ;
cout << "Would you like to enter a new height and weight? (y or n): " ;
cin >> Repeat ;
return main () ;
}
else (Repeat = 'n')
DoItAgain = false ;
return 0 ;
}
int BMICalc(int weight, int height)
{
int wgt_kg ; // weight in kilograms
int hgt_m ; // height in meters
wgt_kg = (weight * 0.454) ; // kilograms = pounds * 0.454
hgt_m = (height * 0.0254) ; // meters = inches * 0.0254)
return (wgt_kg/(hgt_m*hgt_m)) ; // BMI = kg/m^2
}