# Unresolved external 'convert(float, float)'

• 05-20-2003
Ipsec Espah
Unresolved external 'convert(float, float)'
Anyone know why i'm getting the following error?
[C++ Warning] Unit1.cpp(24): W8054 Style of function definition is now obsolete
[Linker Error] Unresolved external 'convert(float, float)' referenced from C:\Program Files\Borland\Cbuilder6\Projects\Project2\Unit1.ob j

Code:

```#include <clx.h> #include <iostream> #pragma hdrstop #pragma argsused using namespace std; float convert(float, float); int main(int argc, char* argv[]) {         cout.setf(ios_base::floatfield);         float height, pounds, BMI;         cout << "Enter your height in feet and inches: ";         cin >> height;         cout << "Enter your weight in pounds: ";         cin >> pounds;         BMI = convert(height, pounds);         cout << "Your Body Mass Index is " << BMI << ".";         return 0; } float convert(height, pounds) {         float inches, meters, kilograms, BMI;         inches = height * 12;         meters = inches * 0.0254;         kilograms = pounds / 2.2;         BMI = kilograms / meters * meters;         return BMI; }```
I'm sure this code isn't exactly right and theres better ways of writing it... If someone wouldn't mind giving a go at this and helping me understand why there way is better i'd appriciate it :) For some reason i think i might have added a little to many floats...

Heres the question:
Write a short program that asks for your height in feet and inches, and your weight in pounds. Use three variables to store the information. Have the program report your Body Mass Index. To calculate the BMI, first convert yoru height in feet and inches to your height in inches. Then, convert your height in inches to your height in meters by multiplying by 0.0254. Then, convert your weight in pounds into your mass in kilograms by dividing by 2.2. Finally, compute your BMI by dividing your mass in kilograms by the square of your height in meters. Use symbolic constrants to represent the various conversion factors.
• 05-20-2003
Zach L.
C++Builder gives the "obsolete style" error when it thinks you are writing a C-style function - one which does not specify argument type until inside the function body.

Your problem is here that

float convert(height, pounds)

should be

float convert(float height, float pounds)

Hope this helps.
• 05-20-2003
KneeGrow
also make your prototype on the top also says the float convert(float height, float pounds)
• 05-20-2003
Zach L.
Okay, and responding to your second question (which I somehow completely missed earlier), you can cut down on the number of floats you use by directly modifying the arguments. An example,

height *= 12 * 0.0254;
pounds /= 2.2; // Though perhaps 'weight' is a more appropriate name for it now

Also, because of order of operations, your function is only returning weight in kilograms right now (equivalent to b/a*a = a*(b/a) = b ), so you might want parenthesis around the 'meters' variable.
• 05-21-2003
Ipsec Espah
Got it, thanks man