954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

New To Boards and C++.. Help

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!!

coolbreeze
Newbie Poster
15 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

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

int feet,inches
cin >> feet >> inches;
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

coolbreeze
Newbie Poster
15 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

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;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

tracethepath
Junior Poster in Training
54 posts since Jul 2007
Reputation Points: 8
Solved Threads: 4
 

Decimal places require float or double variables.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You