Challenge 8b

Description

The purpose of this challenge is to use basic functions. This challenge will calculate BMI (Body Mass Index).

Requirements

  1. Create a function, char showmenu() as below
    char showmenu()
    {
      char input;
      
      cout << "i - Enter imperial data" << endl;
      cout << "m - Enter metric data" << endl;
      cout << "q - Quit" << endl;
      cin >> input;
    
      return input;
    }
  2. Create the following function prototypes. You will, of course, be expected to write the complete function definitions as well.
    double calc_bmi(double height, double weight);
    double height_to_metric(double value);
    double weight_to_metric(double value);

    The calc_bmi() function will perform the BMI calculation. The returned value will be the resulting BMI. To calculate BMI, both the height and weight values must be in metric.

    BMI = weight / height2

  3. The height_to_metric() function will convert the value parameter from inches to meters (the returned value). The weight_to_metric() function will convert the value parameter from pounds to kilograms (the returned value). Use the following conversion factors below.
    1 meter = 39.3701 inches (LENGTH conversions)
    1 kg = 2.20462 lb.  (WEIGHT conversions)
    
  4. Use the sample main below as a structural flow guide.
  5. Display the results to the user.

 Sample main()

int main()
{
  char menu;
  double feet, inches, meters, bmi, lbs, kg;

  do
  {
    menu = showmenu();

    if (menu == 'i')
    {
      // ask user to enter height in feet and inches
      // ask user to enter weight in lbs 

      // convert all info to metric
    }

    if (menu == 'm')
    {
      // ask user to enter height in meters
      // ask user to enter weight in kg
    }

    if (menu != 'q')
    {
      // calculate BMI

      // display BMI info
      cout << "Your BMI is " << bmi << endl;    
    }

  } while (menu != 'q');
  return 0;
}

Sample Interaction / Output

$./a.out
i - Enter imperial data
m - Enter metric data
q - Quit
i
Okay, using imperial…

Enter height in feet and inches: 6 1
Enter weight in lbs: 135
Your BMI is 17.811
i - Enter imperial data
m - Enter metric data
q - Quit
m

Okay, using metric… 
Enter height in meters: 1.5 
Enter weight in kg: 60 
Your BMI is 26.6667

i - Enter imperial data
m - Enter metric data
q - Quit
q

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0008b

Print Requirements