New To Boards and C++.. Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 15
Reputation: coolbreeze is an unknown quantity at this point 
Solved Threads: 0
coolbreeze coolbreeze is offline Offline
Newbie Poster

New To Boards and C++.. Help

 
0
  #1
Oct 16th, 2007
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:
  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. double weight, height;
  7. string name;
  8. int BMI;
  9.  
  10. cout<< "Enter Your Name: ";
  11. cin>> name;
  12.  
  13. cout<< "Enter Your Weight In Pounds: ";
  14. cin>> weight;
  15.  
  16. cout<< "Enter Your Height In Feet And Inches: ";
  17. cin>> height;
  18.  
  19. BMI = ((weight)/((height) * (height))* 703);
  20.  
  21. cout<< name << " weighs " << weight<< " pounds and is " <<height;
  22. cout<<" inches tall "<<endl;
  23.  
  24. cout<<name<< " has a BMI of " <<BMI<< " which is " <<BMI<<endl;
  25.  
  26. if(BMI <= 19)
  27. {
  28. cout<<"Too Low!"<<endl;
  29. }
  30. else if(BMI <= 25)
  31. {
  32. cout<<"Just Right!"<<endl;
  33. }
  34. else
  35. {
  36. cout<<"Too High!"<<endl;
  37. }
  38.  
  39.  
  40. return 0;
  41.  
  42. }

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!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: New To Boards and C++.. Help

 
0
  #2
Oct 16th, 2007
>>Enter Your Height In Feet And Inches: 5 4
use two variables, not one, something like this
  1. int feet,inches
  2. cin >> feet >> inches;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 15
Reputation: coolbreeze is an unknown quantity at this point 
Solved Threads: 0
coolbreeze coolbreeze is offline Offline
Newbie Poster

Re: New To Boards and C++.. Help

 
0
  #3
Oct 17th, 2007
Thanks for the input.. here is my updated code

  1.  
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.  
  7. double meters, totalInches, kilograms, feet, inches;
  8. string name;
  9. int BMI, pounds;
  10.  
  11. cout<< "Enter Your Name: ";
  12. cin>> name;
  13.  
  14. cout<< "Enter Your Weight In Pounds: ";
  15. cin>> pounds;
  16.  
  17. cout<< "Enter Your Height In Feet And Inches: ";
  18. cin>> feet >> inches;
  19.  
  20. kilograms = (pounds/2.2);
  21. totalInches = ((feet * 12.0) + inches);
  22. meters = (totalInches * .0254);
  23. BMI = ((kilograms)/(meters * meters));
  24.  
  25. cout<< name << " weighs " << pounds<< " pounds and is " <<feet;
  26. cout<<" feet and " <<inches<<" inches tall "<<endl;
  27.  
  28. cout<<name<< " has a BMI of " <<BMI<< " which is " <<endl;
  29.  
  30. if(BMI <= 19)
  31. {
  32. cout<<"Too Low!"<<endl;
  33. }
  34. else if(BMI <= 25)
  35. {
  36. cout<<"Just Right!"<<endl;
  37. }
  38. else
  39. {
  40. cout<<"Too High!"<<endl;
  41. }
  42.  
  43.  
  44. return 0;
  45.  
  46. }


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
Last edited by coolbreeze; Oct 17th, 2007 at 5:58 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1462
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: New To Boards and C++.. Help

 
0
  #4
Oct 17th, 2007
setw I think will do it
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. float n = 123.4567890F;
  8. cout << setw(3) << n << "\n";
  9. return 0;
  10. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 54
Reputation: tracethepath is an unknown quantity at this point 
Solved Threads: 4
tracethepath's Avatar
tracethepath tracethepath is offline Offline
Junior Poster in Training

Re: New To Boards and C++.. Help

 
0
  #5
Oct 18th, 2007
u cn simply use BMI as a float variable...
float BMI;
With Regards...
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: New To Boards and C++.. Help

 
0
  #6
Oct 18th, 2007
Decimal places require float or double variables.
Last edited by WaltP; Oct 18th, 2007 at 5:02 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC