| | |
Menu
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 0
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.
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)
#include <iostream> using namespace std; int main(void) { int pnum; cout << "Please press the number of the calculator you would like to use." << endl << endl; cout << "\n1. BMI Calculator"; cout << "\n2. Body Fat Percentage Calculator\n" << endl; cin >> pnum; }
-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.
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#3 Nov 4th, 2009
Sorry I am very new to this.
Here is the code for the BFP.cpp
and here is the code for the BMI.cpp
So what would I put to call these from the menu?
Here is the code for the BFP.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int BFP(void) { double tweight; double waist; double bodyfp; cout << "Please enter your weight." << endl << endl; cin >> tweight; cout << "\nPlease enter your waist size in inches." << endl << endl; cin >> waist; double leanbmw; leanbmw =((tweight * 1.082) + (94.42)); double leanbmwa; leanbmwa = waist * 4.15; double leanbm; leanbm = leanbmw - leanbmwa; double bfweight; bfweight = (tweight - leanbm); bodyfp = ((bfweight *100) / tweight); if (bodyfp >= 2 && bodyfp <= 4) { cout << "\nYour Body Fat percentage is: " << bodyfp; cout << "\nYour Body Fat percentage classification is Essenntial Fat." << endl; } else if (bodyfp >= 5 && bodyfp <= 13) { cout << "\nYour Body Fat percentage is: " << bodyfp; cout << "\nYour Body Fat percentage classification is Athletes." << endl; } else if (bodyfp >= 14 && bodyfp <= 17){ cout << "\nYour Body Fat percentage is: " << bodyfp; cout << "\nYour Body Fat percentage classification is Fitness." << endl; } else if (bodyfp >= 18 && bodyfp <= 25){ cout << "\nYour Body Fat percentage is: " << bodyfp; cout << "\nYour Body Fat percentage classification is Acceptable." << endl; } else if (bodyfp >= 26){ cout << "\nYour Body Fat percentage is: " << bodyfp; cout << "\tYour Body Fat percentage classification is Obese." << endl << endl; } system("pause"); return 0; }
and here is the code for the BMI.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int BMI() { system("TITLE BMI Calculator"); system("COLOR 1f"); int myweight; int myheight; int mynum; mynum = 703; int mybmi; int squared; cout << "Please enter your weight in pounds." << endl << endl; cin >> myweight; cout << "\nPlease enter your height in inches." <<endl << endl; cin >> myheight; cin.ignore(); squared = (myheight * myheight); mybmi = ((myweight * 703)/squared); if (mybmi < 18.5) { cout << "\nYour BMI is: " << mybmi; cout << "\tYour BMI says you are Underwight." << endl; } else if (mybmi >= 18.5 && mybmi < 24.5) { cout << "\nYour BMI is: " << mybmi; cout << "\tYour BMI says you are Normal." << endl; } else if (mybmi >= 24.5 && mybmi <29.9){ cout << "\nYour BMI is: " << mybmi; cout << "\tYour BMI says you are Overwight." << endl; } else if (mybmi >= 30){ cout << "\nYour BMI is: " << mybmi; cout << "\tYour BMI says you are Obese." << endl; } cin.get(); system("pause"); return 0; }
So what would I put to call these from the menu?
-7
#4 Nov 4th, 2009
After line 12 or the code you originally posted, create a switch statement and call either BFP() or BMI().
C++ Syntax (Toggle Plain Text)
switch( pnum ) { case 1: BFP(); break; case 2: BMI(); break; default: cout << "Huh??\n"; break; }
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.
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Nov 2009
Posts: 17
Reputation:
Solved Threads: 0
0
#7 Nov 4th, 2009
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "BMI.cpp" #include "BFP.cpp" using namespace std; int main(void) { int pnum; cout << "Please press the number of the calculator you would like to use." << endl << endl; cout << "\n1. BMI Calculator"; cout << "\n2. Body Fat Percentage Calculator\n" << endl; cin >> pnum; if(pnum<1||pnum>2){ cout<<"Invalid choice."<<endl; return 1; } switch( pnum ) { case 1: BFP(); break; case 2: BMI(); break; } return 0; }
-7
#10 Nov 4th, 2009
1) Create another loop
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.
C++ Syntax (Toggle Plain Text)
int main() { while( true ) { // blabla } }
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.
![]() |
Similar Threads
- JS jump menu location indexing on search engines (JavaScript / DHTML / AJAX)
- Menu does not work (ASP.NET)
- Windows New Menu (Windows NT / 2000 / XP)
- Start up Menu problems (Windows NT / 2000 / XP)
- Unwanted file in run menu (Windows NT / 2000 / XP)
- IE 6.0 doesn't show address bar, pull-down menu and shortcut icons when opened (Web Browsers)
- IE 6.0 doesn't show address bar, pull-down menu & short-cut icons when opened (Windows NT / 2000 / XP)
- Canot get file buttons or menu bars to display in i.e. (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: what is the path to move to every point of a matrix of 5 column and 5 row once?????
- Next Thread: Create UNIX Shell Pipes handler
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






