944,084 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 622
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 4th, 2009
0

Menu

Expand Post »
I want to create a menu. The files i have are main.cpp BMI.cpp and BFP.cpp.
I want the program to use the BMI.cpp when 1 is pressed and the BFP.ccp when 2 is pressed. Here is my code so far.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(void)
  5.  
  6. {
  7. int pnum;
  8.  
  9. cout << "Please press the number of the calculator you would like to use." << endl << endl;
  10. cout << "\n1. BMI Calculator";
  11. cout << "\n2. Body Fat Percentage Calculator\n" << endl;
  12. cin >> pnum;
  13.  
  14.  
  15.  
  16. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skarocks47 is offline Offline
17 posts
since Nov 2009
Nov 4th, 2009
-7
Re: Menu
You can't call *.cpp files, but methods and functions that reside in the files. If you want to call IBM.cpp then call one of the functions or methods that is coded in that file.
Last edited by Ancient Dragon; Nov 4th, 2009 at 2:52 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,957 posts
since Aug 2005
Nov 4th, 2009
0
Re: Menu
Sorry I am very new to this.

Here is the code for the BFP.cpp
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int BFP(void)
  5. {
  6.  
  7. double tweight;
  8. double waist;
  9. double bodyfp;
  10. cout << "Please enter your weight." << endl << endl;
  11. cin >> tweight;
  12.  
  13. cout << "\nPlease enter your waist size in inches." << endl << endl;
  14. cin >> waist;
  15.  
  16. double leanbmw;
  17. leanbmw =((tweight * 1.082) + (94.42));
  18. double leanbmwa;
  19. leanbmwa = waist * 4.15;
  20. double leanbm;
  21. leanbm = leanbmw - leanbmwa;
  22. double bfweight;
  23. bfweight = (tweight - leanbm);
  24.  
  25.  
  26. bodyfp = ((bfweight *100) / tweight);
  27.  
  28.  
  29.  
  30. if (bodyfp >= 2 && bodyfp <= 4) {
  31. cout << "\nYour Body Fat percentage is: " << bodyfp;
  32. cout << "\nYour Body Fat percentage classification is Essenntial Fat." << endl;
  33. }
  34. else if (bodyfp >= 5 && bodyfp <= 13) {
  35. cout << "\nYour Body Fat percentage is: " << bodyfp;
  36. cout << "\nYour Body Fat percentage classification is Athletes." << endl;
  37. }
  38. else if (bodyfp >= 14 && bodyfp <= 17){
  39. cout << "\nYour Body Fat percentage is: " << bodyfp;
  40. cout << "\nYour Body Fat percentage classification is Fitness." << endl;
  41. }
  42. else if (bodyfp >= 18 && bodyfp <= 25){
  43. cout << "\nYour Body Fat percentage is: " << bodyfp;
  44. cout << "\nYour Body Fat percentage classification is Acceptable." << endl;
  45. }
  46. else if (bodyfp >= 26){
  47. cout << "\nYour Body Fat percentage is: " << bodyfp;
  48. cout << "\tYour Body Fat percentage classification is Obese." << endl << endl;
  49. }
  50.  
  51.  
  52.  
  53. system("pause");
  54.  
  55. return 0;
  56.  
  57. }


and here is the code for the BMI.cpp

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int BMI()
  5.  
  6. {
  7. system("TITLE BMI Calculator");
  8. system("COLOR 1f");
  9.  
  10. int myweight;
  11. int myheight;
  12. int mynum;
  13. mynum = 703;
  14. int mybmi;
  15. int squared;
  16.  
  17.  
  18. cout << "Please enter your weight in pounds." << endl << endl;
  19. cin >> myweight;
  20.  
  21. cout << "\nPlease enter your height in inches." <<endl << endl;
  22. cin >> myheight;
  23. cin.ignore();
  24.  
  25. squared = (myheight * myheight);
  26. mybmi = ((myweight * 703)/squared);
  27.  
  28.  
  29. if (mybmi < 18.5) {
  30. cout << "\nYour BMI is: " << mybmi;
  31. cout << "\tYour BMI says you are Underwight." << endl;
  32. }
  33. else if (mybmi >= 18.5 && mybmi < 24.5) {
  34. cout << "\nYour BMI is: " << mybmi;
  35. cout << "\tYour BMI says you are Normal." << endl;
  36. }
  37. else if (mybmi >= 24.5 && mybmi <29.9){
  38. cout << "\nYour BMI is: " << mybmi;
  39. cout << "\tYour BMI says you are Overwight." << endl;
  40. }
  41. else if (mybmi >= 30){
  42. cout << "\nYour BMI is: " << mybmi;
  43. cout << "\tYour BMI says you are Obese." << endl;
  44. }
  45.  
  46.  
  47. cin.get();
  48.  
  49.  
  50. system("pause");
  51.  
  52. return 0;
  53.  
  54. }


So what would I put to call these from the menu?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skarocks47 is offline Offline
17 posts
since Nov 2009
Nov 4th, 2009
-7
Re: Menu
After line 12 or the code you originally posted, create a switch statement and call either BFP() or BMI().
C++ Syntax (Toggle Plain Text)
  1. switch( pnum )
  2. {
  3. case 1:
  4. BFP();
  5. break;
  6. case 2:
  7. BMI();
  8. break;
  9. default:
  10. cout << "Huh??\n";
  11. break;
  12. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,957 posts
since Aug 2005
Nov 4th, 2009
0
Re: Menu
So i followed your directions and i keep getting this error.

main.obj : error LNK2005: "int __cdecl BMI(void)" (?BMI@@YAHXZ) already defined in BMI.obj
main.obj : error LNK2005: "int __cdecl BFP(void)" (?BFP@@YAHXZ) already defined in BFP.obj
C:\Users\xxxxx\Documents\Visual Studio 2008\Projects\Health Calculators\Debug\Health Calculators.exe : fatal error LNK1169: one or more multiply defined symbols found
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skarocks47 is offline Offline
17 posts
since Nov 2009
Nov 4th, 2009
-7
Re: Menu
post the entire main.cpp.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,957 posts
since Aug 2005
Nov 4th, 2009
0
Re: Menu
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include "BMI.cpp"
  3. #include "BFP.cpp"
  4. using namespace std;
  5.  
  6. int main(void)
  7.  
  8. {
  9. int pnum;
  10.  
  11. cout << "Please press the number of the calculator you would like to use." << endl << endl;
  12. cout << "\n1. BMI Calculator";
  13. cout << "\n2. Body Fat Percentage Calculator\n" << endl;
  14. cin >> pnum;
  15.  
  16. if(pnum<1||pnum>2){
  17. cout<<"Invalid choice."<<endl;
  18. return 1;
  19. }
  20.  
  21.  
  22. switch( pnum )
  23. {
  24. case 1:
  25. BFP();
  26. break;
  27. case 2:
  28. BMI();
  29. break;
  30.  
  31. }
  32.  
  33.  
  34. return 0;
  35. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skarocks47 is offline Offline
17 posts
since Nov 2009
Nov 4th, 2009
-7
Re: Menu
Just as I suspected -- you can not include those two *.cpp files in main.cpp. Delete lines 2 and 3, then add function prototypes for each of those two functions.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,957 posts
since Aug 2005
Nov 4th, 2009
0
Re: Menu
Thank you so much! it worked. Couple more questions. what would i need to put in the code in order for it to loop after it completed one of the 2 programs. and second question what could i put in for it to clear the last text after it inputs the number
Reputation Points: 10
Solved Threads: 0
Newbie Poster
skarocks47 is offline Offline
17 posts
since Nov 2009
Nov 4th, 2009
-7
Re: Menu
1) Create another loop
C++ Syntax (Toggle Plain Text)
  1. int main()
  2. {
  3. while( true )
  4. {
  5. // blabla
  6. }
  7. }

2) I don't know what you mean by "clear last text". If you mean clear the screen, don't bother. Just print a couple blank lines and reprint the menu.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,957 posts
since Aug 2005

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: what is the path to move to every point of a matrix of 5 column and 5 row once?????
Next Thread in C++ Forum Timeline: Create UNIX Shell Pipes handler





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


Follow us on Twitter


© 2011 DaniWeb® LLC