Hello to everyone,

Well I'm a noob to C++, I just started two weeks ago, I'm trying to get a good head start before I start college next semester. I've done simple programs, but now I'm trying to create a body fat percentage calculator I guess you could say. but I'm getting some weird errors and for the life of me I can't figure out what I'm doing wrong. Any help would be much obliged. here is the code

#include<iostream>

using namespace std;

int femaleBodyFat (float weight,float waist,float wrist,float hip, float forearm);
int maleBodyFat   (float weight,float waist);

int main()

{
	char  gender;
	float weight, waist, wrist, hip, forearm;
	float bodyFatPercentage;
	
	cout<<"Enter your gender f/F for female or m/M for male:";
	cin>>gender;
	cout<<endl;

	
	if (gender == 'f' || gender == 'F')

	{
	    cout<<"Enter your body weight:";
            cin>>weight;
	    cout<<endl;

	    cout<<"Enter your waist size in inches:";
	    cin>>waist;
	    cout<<endl;

	    cout<<"Enter your wrist size in inches:";
	    cin>>wrist;
	    cout<<endl;

	    cout<<"Enter your hip size in inches:";
	    cin>>hip;
	    cout<<endl;

	    cout<<"Enter your forearm size in inches:";
	    cin>>forearm;
	    cout<<endl;

		
}

	else if (gender == 'm' || gender == 'M')

{
	cout<<"Enter your body weight:";
        cin>>weight;
	cout<<endl;

	cout<<"Enter your waist size in inches:";
	cin>>waist;
	cout<<endl;


}
int femaleBodyFat (float weight,float waist, float wrist, float hip, float forearm);
{

	float A1, A2, A3, A4, A5, b, bf;

A1 = (weight * 0.732) + 8.987;
A2 = wrist / 3.140;
A3 = waist * 0.157;
A4 = hip * 0.249;
A5 = forearm * 0.434;
b =  A1 + A2 - A3 - A4 + A5;
bf = weight - b;

return bf * 100.00 / weight;

}
  int maleBodyFat (float weight, float waist); 
{
	
 float	A1, A2, b, bf;

A1 = (weight * 1.082) + 94.42;
A2 = waist * 4.15;
b =  A1 - A2;
bf = weight - b;

return bf * 100 / weight;

}

if (gender == 'f' || gender == 'F')

{
	bodyFatPercentage = femaleBodyFat (weight, waist, wrist, hip, forearm)
}

else if (gender == 'm' || gender == 'M')

{
	bodyFatPercentage = maleBodyFat (weight, waist)
}

	
	cout<<"Your Body Fat Percentage is:" <<bodyFatPercentage<<endl;
	system("pause");

	return 0;

}

///here are the errors I'm getting///


1>------ Build started: Project: bodyfatcalculator, Configuration: Debug Win32 ------
1>Build started 9/29/2010 2:19:38 PM.
1>InitializeBuildStatus:
1> Creating "Debug\bodyfatcalculator.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> bodyfatcalculator.cpp
bodyfatcalculator.cpp(64): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(65): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(66): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(67): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(68): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(72): warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data
(80): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(81): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(85): warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data
(93): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
(93): error C2143: syntax error : missing ';' before '}'
(99): warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
(99): error C2143: syntax error : missing ';' before '}'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.07
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Hi,

You had an error (from what I can work out) by trying to define the function in the main class.

Edit: I am using Visual C++ 2010 Express, but should work in other versions

I only get warnings from this code (possible loss of data):

#include<iostream>

using namespace std;

int femaleBodyFat (float weight,float waist,float wrist,float hip, float forearm);
int maleBodyFat   (float weight,float waist);

int main()
{
	char  gender;
	float weight, waist, wrist, hip, forearm;
	float bodyFatPercentage;
	
	cout<<"Enter your gender f/F for female or m/M for male:";
	cin>>gender;
	cout<<endl;

	
	if (gender == 'f' || gender == 'F')
	{
	    cout<<"Enter your body weight:";
        cin>>weight;
	    cout<<endl;

	    cout<<"Enter your waist size in inches:";
	    cin>>waist;
	    cout<<endl;

	    cout<<"Enter your wrist size in inches:";
	    cin>>wrist;
	    cout<<endl;

	    cout<<"Enter your hip size in inches:";
	    cin>>hip;
	    cout<<endl;

	    cout<<"Enter your forearm size in inches:";
	    cin>>forearm;
	    cout<<endl;

		
	}
	else if (gender == 'm' || gender == 'M')
	{
		cout<<"Enter your body weight:";
		cin>>weight;
		cout<<endl;

		cout<<"Enter your waist size in inches:";
		cin>>waist;
		cout<<endl;


	}


	if (gender == 'f' || gender == 'F')
	{
		bodyFatPercentage = femaleBodyFat(weight, waist, wrist, hip, forearm);
	}
	else if (gender == 'm' || gender == 'M')
	{
		bodyFatPercentage = maleBodyFat(weight, waist);
	}

	
	cout<<"Your Body Fat Percentage is:" <<bodyFatPercentage<<endl;
	system("pause");

	return 0;

}

int femaleBodyFat (float weight,float waist, float wrist, float hip, float forearm)
{

	float A1, A2, A3, A4, A5, b, bf;

	A1 = (weight * 0.732) + 8.987;
	A2 = wrist / 3.140;
	A3 = waist * 0.157;
	A4 = hip * 0.249;
	A5 = forearm * 0.434;
	b =  A1 + A2 - A3 - A4 + A5;
	bf = weight - b;

	return bf * 100.00 / weight;
}

int maleBodyFat (float weight, float waist)
{
	float	A1, A2, b, bf;

	A1 = (weight * 1.082) + 94.42;
	A2 = waist * 4.15;
	b =  A1 - A2;
	bf = weight - b;

	return bf * 100 / weight;
}

The warnings are nothing really. Hope this helps.

Kieran :)

Checking out Kieran's code: works fine. Just a couple of points. When it asks for your body weight, is that kilograms or what? Good job guys :)

Thanks so much Kieran, it worked out great,I didn't have the ;, and when I did it and ran it, it gave me a link error, but I fixed that no problem.
SgtMe your right I should say lbs. or kilograms, Thanks a lot to both of you, and I'm glad to be part of the community

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.