Unresolved external 'convert(float, float)'

This is a discussion on Unresolved external 'convert(float, float)' within the C++ Programming forums, part of the General Programming Boards category; Anyone know why i'm getting the following error? [C++ Warning] Unit1.cpp(24): W8054 Style of function definition is now obsolete [Linker ...

  1. #1
    Ipsec Espah
    Guest

    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.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    195
    also make your prototype on the top also says the float convert(float height, float pounds)

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.

  5. #5
    Ipsec Espah
    Guest

    Thumbs up

    Got it, thanks man

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 04:25 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21