Question: Please help with c++, i keep getting errors on my code, anyone knows how to change the code from if/else to case statements?? Using the

Please help with c++, i keep getting errors on my code, anyone knows how to change the code from if/else to case statements??

Using the code template in the lectures page:

1. Edit code so that the user can enter upper or lower case f or m using a string property.

2. Edit the code from if/else to case statements

// Chapter 4 Exer 18 // BMI #include #include #include

using namespace std;

int main() { // Variables input by user char gender;

double bodyWeight; double wristMeasurementAtFullestPoint; double waistMeasurementAtNavel; double hipMeasurementAtFullestPoint; double forearmMeasurementAtFullestPoint; double waistMeasurementAtFullestPoint;

// Variables used for calculations double A1, A2, A3, A4, A5; double B; double bodyFat; double bodyFatPercentage;

cout << "Enter your gender (F or M): "; cin >> gender; cout << endl;

// Female BMI if (gender == 'F' || gender == 'f') { cout << "Enter body weight (in pounds): "; cin >> bodyWeight; cout << endl;

cout << "Enter wrist measurement at fullest point (in inches): "; cin >> wristMeasurementAtFullestPoint; cout << endl;

cout << "Enter waist measurement at navel (in inches): "; cin >> waistMeasurementAtNavel; cout << endl;

cout << "Enter hip measurement at fullest point (in inches): "; cin >> hipMeasurementAtFullestPoint; cout << endl;

cout << "Enter forearm measurement at fullest point (in inches): "; cin >> forearmMeasurementAtFullestPoint; cout << endl;

// BMI Calculations A1 = bodyWeight * 0.732 + 8.987; A2 = wristMeasurementAtFullestPoint / 3.140; A3 = waistMeasurementAtNavel * 0.157; A4 = hipMeasurementAtFullestPoint * 0.249; A5 = forearmMeasurementAtFullestPoint * 0.434; B = A1 + A2 - A3 - A4 + A5; bodyFat = bodyWeight - B; bodyFatPercentage = bodyFat * 100 / bodyWeight;

cout << "Body fat: " << bodyFat << endl; cout << "Body fat percentage: " << bodyFatPercentage << endl; } // Male BMI else if (gender == 'M' || gender == 'm') { cout << "Enter body weight (in pounds): "; cin >> bodyWeight; cout << endl;

cout << "Enter waist measurement at fullest point (in inches): "; cin >> waistMeasurementAtFullestPoint; cout << endl;

// BMI Calculations A1 = bodyWeight * 1.082 + 94.42; A2 = waistMeasurementAtFullestPoint * 4.15; B = A1 - A2; bodyFat = bodyWeight - B; bodyFatPercentage = bodyFat * 100 / bodyWeight;

cout << "Body fat: " << bodyFat << endl; cout << "Body fat percentage: " << bodyFatPercentage << endl; } else { cout << "Invalid gender code." << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!