Menu

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

Join Date: Nov 2009
Posts: 17
Reputation: skarocks47 is an unknown quantity at this point 
Solved Threads: 0
skarocks47 skarocks47 is offline Offline
Newbie Poster

Menu

 
0
  #1
Nov 4th, 2009
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.

  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #2
Nov 4th, 2009
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.
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: Nov 2009
Posts: 17
Reputation: skarocks47 is an unknown quantity at this point 
Solved Threads: 0
skarocks47 skarocks47 is offline Offline
Newbie Poster
 
0
  #3
Nov 4th, 2009
Sorry I am very new to this.

Here is the code for the BFP.cpp
  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

  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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #4
Nov 4th, 2009
After line 12 or the code you originally posted, create a switch statement and call either BFP() or BMI().
  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. }
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: Nov 2009
Posts: 17
Reputation: skarocks47 is an unknown quantity at this point 
Solved Threads: 0
skarocks47 skarocks47 is offline Offline
Newbie Poster
 
0
  #5
Nov 4th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #6
Nov 4th, 2009
post the entire main.cpp.
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: Nov 2009
Posts: 17
Reputation: skarocks47 is an unknown quantity at this point 
Solved Threads: 0
skarocks47 skarocks47 is offline Offline
Newbie Poster
 
0
  #7
Nov 4th, 2009
  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #8
Nov 4th, 2009
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.
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: Nov 2009
Posts: 17
Reputation: skarocks47 is an unknown quantity at this point 
Solved Threads: 0
skarocks47 skarocks47 is offline Offline
Newbie Poster
 
0
  #9
Nov 4th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,648
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #10
Nov 4th, 2009
1) Create another loop
  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.
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  
Reply

Message:




Views: 334 | Replies: 11
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC