Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions