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.

#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;
	
	

}

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.

Sorry I am very new to this.

Here is the code for the BFP.cpp

#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

#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?

After line 12 or the code you originally posted, create a switch statement and call either BFP() or BMI().

switch( pnum )
{
    case 1:
          BFP();
          break;
    case 2:
          BMI();
          break;
    default:
         cout << "Huh??\n";
         break;
}

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

post the entire main.cpp.

#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;
}

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.

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

1) Create another loop

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.

I thank you for your help. But i cant seem to implement the loop. I just want it to loop back to the main menu after each of the programs run.

Can anyone help me understand how to implement the loop?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.