Hey guys, I'm new to this board and C++ and was looking for a little help or guidance on this program my professor assigned. She assigned the class to create a BMI Calculator, and I have all the nessesary input given for it to work perfect but im not sure how to do some things on my output. Here is my code:

#include <iostream>
using namespace std;
int main()
{
double weight, height;
string name;
int BMI;

cout<< "Enter Your Name: ";
cin>> name;

cout<< "Enter Your Weight In Pounds: ";
cin>> weight;

cout<< "Enter Your Height In Feet And Inches: ";
cin>> height;

BMI = ((weight)/((height) * (height))* 703);

cout<< name << " weighs " << weight<< " pounds and is " <<height;
cout<<" inches tall "<<endl;

cout<<name<< " has a BMI of " <<BMI<< " which is " <<BMI<<endl;

if(BMI <= 19)
{
        cout<<"Too Low!"<<endl;
}
else if(BMI <= 25)
{
        cout<<"Just Right!"<<endl;
}
else
{
        cout<<"Too High!"<<endl;
}


return 0;

}

Now, it comiles and runs smooth, but their are some things that need to change that i'm not sure how to do. I'll show you my output, and then i'll show you the output that she wants us to have.

Here is my output:

Enter Your Name: Craig
Enter Your Weight In Pounds: 132
Enter Your Height In Feet And Inches: 64
Craig weighs 132 pounds and is 64 inches tall
Craig has a BMI of 22 which is 22
Just Right!


Here is the output I need to be getting(I'll just type it in)
Enter Your Name: Craig
Enter Your Weight in Pounds: 132
Enter Your Height In Feet And Inches: 5 4 //trying to get that input with a space since i'm 5'4
Craig weighs 132 pounds and is 5 feet 4 inches tall (trying to get that instead of just inches)
Craig has a BMI of 22(needs to be 3 decimal places) which is Just Right! (Instead of the extra 22 number, I need to replace it with the if, else if, else statement.


Thanks so much for all the help!!

Recommended Answers

All 5 Replies

>>Enter Your Height In Feet And Inches: 5 4
use two variables, not one, something like this

int feet,inches
cin >> feet >> inches;

Thanks for the input.. here is my updated code

#include <iostream>
using namespace std;
int main()
{

double meters, totalInches, kilograms, feet, inches;
string name;
int BMI, pounds;

cout<< "Enter Your Name: ";
cin>> name;

cout<< "Enter Your Weight In Pounds: ";
cin>> pounds;

cout<< "Enter Your Height In Feet And Inches: ";
cin>> feet >> inches;

kilograms = (pounds/2.2);
totalInches = ((feet * 12.0) + inches);
meters = (totalInches * .0254);
BMI = ((kilograms)/(meters * meters));

cout<< name << " weighs " << pounds<< " pounds and is " <<feet;
cout<<" feet and " <<inches<<" inches tall "<<endl;

cout<<name<< " has a BMI of " <<BMI<< " which is " <<endl;

if(BMI <= 19)
{
        cout<<"Too Low!"<<endl;
}
else if(BMI <= 25)
{
        cout<<"Just Right!"<<endl;
}
else
{
        cout<<"Too High!"<<endl;
}


return 0;

}

I edited some things to make it work, But I need to ask one more question. I need to get the BMI into a decimal form, 3 decimals to be exact. Anyone got any suggestions?!

thanks very much

setw I think will do it

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    float n = 123.4567890F;
    cout << setw(3) <<  n << "\n";
    return 0;
}

u cn simply use BMI as a float variable...
float BMI;

Decimal places require float or double variables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.