Question: For the Problem 3 that you have accomplished in Assignment 1 , you will group all variables, including array variables into a struct to practice

For the Problem 3 that you have accomplished in Assignment 1, you will group all variables, including array variables into a struct to practice grouping variables. So, you will basically go ahead and copy the code that you have done from Assignment 1 and replace variable name with struct and initialize the struct via objects and ensure that the whole program flow reflects the struct access.
Problem 3:
#include
#include
using namespace std;
int main(){
// Declare variables
string name, gender;
int age, heightFeet, heightInches;
double weightInPounds;
// Ask the user to enter their information
cout << "Please enter your name: ";
getline(cin, name);
cout << "Please enter your age: ";
cin >> age;
cout << "Please enter your Gender (male/female): ";
cin.ignore();
getline(cin, gender);
cout << "Please enter your height in feet: ";
cin >> heightFeet;
cout << "Please enter your height in inches: ";
cin >> heightInches;
cout << "Please enter your weight in pounds: ";
cin >> weightInPounds;
// Calculate BMI
int heightInInches =(heightFeet *12)+ heightInches;
double bmi =(703* weightInPounds)/(heightInInches * heightInInches);
// Determine BMI category
string bmiCategory;
if (bmi <16){
bmiCategory = "Severe Thinness";
} else if (bmi <17){
bmiCategory = "Moderate Thinness";
} else if (bmi <18.5){
bmiCategory = "Mild Thinness";
} else if (bmi <25){
bmiCategory = "Normal";
} else if (bmi <30){
bmiCategory = "Overweight";
} else if (bmi <35){
bmiCategory = "Obese Class I";
} else if (bmi <40){
bmiCategory = "Obese Class II";
} else {
bmiCategory = "Obese Class III";
}
// Output user information and BMI category
cout <<"
Hi "<< name <<","<< endl;
cout << "You are a "<< gender <<". You are "<< age <<" years old." << endl;
cout << "You are currently "<< heightFeet <<"'"<< heightInches <<"\" and you currently weigh "<< weightInPounds <<" pounds." << endl;
cout << "Your BMI is "<< bmi <<", which is "<< bmiCategory <<"."<< endl;
cout <<"
Thank you for using the BMI Calculator!" << 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 Programming Questions!