943,946 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1309
  • C++ RSS
Oct 16th, 2007
0

New To Boards and C++.. Help

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  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!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
coolbreeze is offline Offline
15 posts
since Oct 2007
Oct 16th, 2007
0

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

>>Enter Your Height In Feet And Inches: 5 4
use two variables, not one, something like this
C++ Syntax (Toggle Plain Text)
  1. int feet,inches
  2. cin >> feet >> inches;
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 17th, 2007
0

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

Thanks for the input.. here is my updated code

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
coolbreeze is offline Offline
15 posts
since Oct 2007
Oct 17th, 2007
0

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

setw I think will do it
C++ Syntax (Toggle Plain Text)
  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. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Oct 18th, 2007
0

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

u cn simply use BMI as a float variable...
float BMI;
Reputation Points: 8
Solved Threads: 4
Junior Poster in Training
tracethepath is offline Offline
54 posts
since Jul 2007
Oct 18th, 2007
0

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

Decimal places require float or double variables.
Last edited by WaltP; Oct 18th, 2007 at 5:02 am.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,741 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Is my if statement a valid statement?
Next Thread in C++ Forum Timeline: Help counting in an array.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC