Thread: Compiling Error, cannot figure out

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    16

    Compiling Error, cannot figure out

    Hey people, this error is probably really easy for you, but i dont know whats up. Here is where my errors are i think:

    ----------------------Start-----
    compute_costs ( id_number, room_length, room_width, flooring_unit_cost,
    flooring_pad_unit_cost, cost_of_labor_per_sq_yd,
    flooring_cost, pad_cost, labor_cost, total_discount );
    ----- end

    It says here that the Code called to undefined function 'compute_costs'.

    It also says in this same area that total_discount is undefined. where do I define it? In the int main function where this output of "compute_costs" is?





    Thanks a lot, if you need any more info, plwease let me know

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    I assume that is the fxn prototype. of what type are the parameters? int, double, char ?

    also, it's most likely where you call compute_costs, you probably did not provide sufficient parameters.

    try and figure it out with this, but if you need more help, more code is needed.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    16
    I'll post the whole program. its sorta long. Forgive me if its not appropriate.

    ------ Code Beg0n-----------------------------------





    #include <iostream>
    #include <iomanip>
    #include <cstring>
    #include <math.h>

    double get_square_yards( double length, double width );
    double calc_flooring_pad_cost( double unit_cost, double square_yardage );
    double calc_cost_of_labor ( double labor_unit_cost, double square_yardage );
    void find_discount ( string id_number, double & carpet_discount, double & pad_discount,
    double & labor_discount );
    void print_receipt();


    int main()
    {
    string id_number, type_of_room, type_of_flooring, color_of_carpet;
    double room_length, room_width, flooring_unit_cost, room_square_yardage;
    double flooring_cost, flooring_pad_unit_cost, pad_cost, cost_of_labor_per_sq_yd;
    double labor_cost;

    flooring_pad_unit_cost = 2.25;
    cost_of_labor_per_sq_yd = 2.40;

    // Get customer id number.
    cout << "Please enter your 5 digit identification number: ";
    cin >> id_number;

    if ( id_number.length() != 5 )
    {
    cout << "Your identification number should be 5 digits long." << endl;
    return 1;
    }


    // get type of room
    cout << "What room would you like new flooring for ('diningroom', 'livingroom', 'bedroom', 'study')? ";
    cin >> type_of_room;

    // get dimensions of room
    cout << "What is the length of the room (in feet)?";
    cin >> room_length;
    cout << "What is the width of the room (in feet)?";
    cin >> room_width;

    // get type of flooring
    cout << "What type of flooring are you purchasing ('carpet', or 'wood_flooring')?";
    cin >> type_of_flooring;

    // get color of carpet if the flooring is actually carpet
    if ( type_of_flooring == "carpet" )
    {
    cout << "What color carpet are you purchasing?";
    cin >> color_of_carpet;
    }

    // get flooring cost per square yard
    cout << "How much does the " << type_of_flooring << " cost per square yard?";
    cin >> flooring_unit_cost;

    compute_costs ( id_number, room_length, room_width, flooring_unit_cost,
    flooring_pad_unit_cost, cost_of_labor_per_sq_yd,
    flooring_cost, pad_cost, labor_cost, total_discount );

    }

    void compute_costs (
    string id,
    double room_length,
    double room_width,
    double flooring_unit_cost,
    double flooring_pad_unit_cost,
    double labor_unit_cost,
    double & flooring_cost,
    double & pad_cost,
    double & labor_cost,
    double & total_discount
    )
    {
    double carpet_disc, pad_disc, labor_disc;
    double room_area;

    find_discount ( id, carpet_disc, pad_disc, labor_disc );

    room_area = ceil ( room_length * room_width / 9.0 );

    flooring_cost = room_area * flooring_unit_cost;
    pad_cost = room_area * flooring_pad_unit_cost;
    labor_cost = room_area * labor_unit_cost;

    total_discount =
    ( flooring_cost * carpet_disc ) +
    ( pad_cost * pad_disc ) +
    ( labor_cost * labor_disc );
    }

    void find_discount ( string id, double & carpet, double & pad, double & labor )
    {
    carpet = 0.0;
    pad = 0.0;
    labor = 0.0;

    if ( id == "81429" )
    {
    carpet = 0.08;
    labor = 0.06;
    }
    else if ( id == "04246" )
    {
    carpet = 0.12;
    pad = 0.12;
    labor = 0.12;
    }
    else if ( id == "39050" )
    {
    // No discount.
    }
    else if ( id >= "00001" && id <= "10000" )
    {
    carpet = 0.12;
    pad = 0.12;
    labor = 0.12;
    }
    else if ( id >= "10001" && id <= "20000" )
    {
    carpet = 0.10;
    pad = 0.10;
    labor = 0.10;
    }
    else if ( id >= "20001" && id <= "50000" )
    {
    carpet = 0.08;
    pad = 0.08;
    labor = 0.08;
    }
    else if ( id >= "50001" && id <= "70000" )
    {
    carpet = 0.06;
    pad = 0.06;
    labor = 0.06;
    }
    }


    --------------------------------- end code----------------------

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    from a quick scan, compute_costs, needs to be prototyped above main.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    You probably haven't written out what compute_costs() is supposed to do, or you are trying to send parameters to compute_costs() that don't appear in the prototype, or not enough parameters to satisfy the prototype. Given the second error regarding total_discount the error here probably interacts with the first one. Check your global and local variable lists to make sure that total_discount has been declared somewhere before you use it as a parameter. Where you declare it is up to you. You should also give it a meaningful value before you try to send it to a function as a parameter.

    In looking at your code posted as I posted my response initially I can't see any declaration for total_discount before it being passed and no prototype for compute_cost() before it is called.
    Last edited by elad; 04-20-2003 at 11:35 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Compiling Problem
    By Deronius in forum C++ Programming
    Replies: 3
    Last Post: 06-15-2008, 11:23 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. adding an #include stops my program from compiling
    By angelscars in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2005, 05:24 PM
  4. trouble compiling
    By the Wookie in forum Linux Programming
    Replies: 1
    Last Post: 10-26-2005, 10:12 PM
  5. Compiling
    By Dae in forum C++ Programming
    Replies: 7
    Last Post: 06-15-2005, 01:08 AM