Thread: Help me with this compiler error, please?

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77

    Help me with this compiler error, please?

    I've finished the coding for the exercise, but I get this error and I don't know how to solve it.

    Code:
    
    
    
    
    /*1. Take the "menu program" you wrote earlier and break it out into a series of calls to functions for 
         each of the menu items.  Add the calculator and "100 bottles of beer" as two different functions that can be called. */
    
    
    
    
    
    
    #include <iostream>;
    #include <string>;
    
    
    using namespace std;
    
    
    
    
    int food();
    int westernfood();
    int easternfood();
    float calculator();
    
    
    
    
    int drinks();
    int hotdrinks();
    int colddrinks();
    
    
    
    
    float calculator(int food, float price) 
    { 
        float result = food * price;
        return result;
    
    
    }
    
    
    int main() 
    {   
        int choice_main_menu = 0;
    
    
    
    
        cout << "Welcome to Big Mama's restaurant. \n";
        cout << "What would you like to order? (press 1 or 2) \n";
        cout << "1. Food\n";
        cout << "2. Drinks \n";
    
    
        cin >> choice_main_menu;
        
        switch (choice_main_menu)
        {
        case 1: 
            food();
            break;
    
    
        case 2: 
            drinks();
            break;
    
    
        default: 
            cout << "Invalid choice. \n";
    
    
        }
    
    
        system("pause");
        return 0;
    }
    
    
    //FOOD
    int food (int westernfood(), int easternfood())
    {   
        int choice_food_menu = 0;
        
    
    
    
    
        cout << "Which menu food would you like to choose from? ( choose 1 or 2 ) \n";
    
    
        cout << "1. Western food \n";
        cout << "2. Eastern food \n";
    
    
        cin >> choice_food_menu;
        
        switch (choice_food_menu)
        {
        case 1:
            cout << westernfood();
            break;
            
        case 2:
            cout << easternfood();
            break;
    
    
        default:
            cout << "Invalid choices. \n";
        }
    
    
        return choice_food_menu;
        
    }
    
    
    int westernfood()
    {  
        
        //food choices
    
    
        int westernfood = 0;
        int potato_chips;
        int steak;
        int bagels;
        int donuts;
        int hamburger;
        
        
        
    
    
        cout << "Please select one of the following western food: \n";
        cout << "1. Potato chips \n";
        cout << "2. Steak \n";
        cout << "3. Bagels \n";
        cout << "4. Donuts \n";
        cout << "5. Hamburgers \n";
    
    
        cin >> westernfood;
    
    
            switch ( westernfood )
            {
            case 1: 
                cout << "How many bag of potato chips would you like? \n";
                cout << "( 1 bag - $2.50 ) \n";      // in this case, "bag" is food quantity, F, and $5 is the cash amount, C.
                
                cin >> potato_chips;
                
                cout << "That would be $" <<  calculator( potato_chips, 2.50 ) << ".\n";
                break;
    
    
            case 2:
                cout << "How many dish(es) of steak would you like? \n";
                cout << "( 1 dish - $7.20 ) \n";
    
    
                cin >> steak;
                
                cout << "That would be $" << calculator ( steak, 7.20 ) << ".\n";
                break;
    
    
            case 3:
                cout << "How many bag of bagels would you like? \n";
                cout << "( 1 bag - $3.00) \n";
    
    
                cin >> bagels;
    
    
                cout << "That would be $" << calculator ( bagels, 3.00 ) << ".\n";
                break;
    
    
            case 4:
                cout << "How many bag of donuts would you like? \n";
                cout << "( 1 bag - $3.50 )\n";
    
    
                cin >> donuts;
    
    
                cout << "That would be $" << calculator( donuts, 3.50 ) << ".\n";
                break;
    
    
            case 5:
                cout << "How many hamburger(s) would you like? \n";
                cout << "( 1 ham - 1.5 )\n";
    
    
                cin >> hamburger;
    
    
                cout << "That would be $" << calculator ( hamburger, 1.5 ) << ".\n";
                break;
    
    
            default:
                cout << "Invalid choice. See above. \n";
            }
    
    
            return westernfood;
    }
    
    
    
    
    int easternfood()
    {
        int easternfood = 0;
        int fish_balls;
        int laksa;
        int spring_rolls;
        int dim_sum;
        int fried_rice;
    
    
        cout << "Please select one of the following western food \n";
        cout << "1. Fish balls \n";
        cout << "2. Laksa \n";
        cout << "3. Spring rolls \n";
        cout << "4. Dim sum \n";
        cout << "5. Fried rice \n";
    
    
        cin >> easternfood;
    
    
        switch (easternfood)
        {
        case 1:
            cout <<"How many bag of fish balls would you like? \n";
            cout <<" ( 1 bag - $1.20 ) \n";
    
    
            cin >> fish_balls;
    
    
            cout <<"That would be $" << calculator  ( fish_balls, 1.20 ) << ".\n";
            break;
    
    
        case 2:
            cout <<"How many bowl of Laksa would you like? \n";
            cout << " ( 1 bowl - $1.00 ) \n";
    
    
            cin >> laksa;
    
    
            cout << "That would be $" << calculator (laksa, 1.00) << ".\n";
            break;
    
    
        case 3:
            cout << "How many bag of spring rolls would you like? \n";
            cout << "( 1 bag - $1.50 )\n";
    
    
            cin >> spring_rolls;
    
    
            cout << "That would be $" << calculator(spring_rolls,1.50) << ".\n";
            break;
    
    
        case 4:
            cout << "How many bowl of dim sum would you like? \n";
            cout << " ( 1 bowl - 3.50 )\n";
    
    
            cin >> dim_sum;
    
    
            cout << "That would be $" << calculator (dim_sum, 3.50) << ".\n";
            break;
    
    
        case 5:
            cout << "How many dish of fried rice would you like> \n";
            cout << " ( 1 dish - $2.50) \n";
    
    
            cin >> fried_rice;
    
    
            cout << "That would be $" << calculator (fried_rice,2.50) << ".\n";
            break;
    
    
        default:
            cout << "Invalid choice. \n";
        }
    
    
        return easternfood;
    }
    
    
    int drinks()
    {
        cout <<"Which menu of drinks would you like to choose from? ( 1 or 2 )\n";
        cout <<"1. Hot drinks \n";
        cout <<"2. Cold drinks \n";
    
    
        int choice_drink_menu = 0;
    
    
        cin >> choice_drink_menu;
    
    
        switch (choice_drink_menu)
        {
        case 1:
            cout << hotdrinks();
            break;
    
    
        case 2:
            cout << colddrinks();
            break;
    
    
        default:
            cout << "Invalid choice. See above. \n";
        }
    
    
        return choice_drink_menu;
    }
    
    
    int hotdrinks()
    {
        int hotdrinks = 0;
        int hot_toddy;
        int irish_coffee;
        int bishop;
        int cocoa;
        int tea;
    
    
    
    
        cout << "Please choose the hot drink you would like to order. \n";
        cout << "1. Hot toddy \n";
        cout << "2. Irish coffee \n";
        cout << "3. Bishop \n";
        cout << "4. Cocoa \n";
        cout << "5. Tea \n";
        
        cin >> hotdrinks;
    
    
        switch (hotdrinks)
        {
        case 1:
            cout <<"How many cup of hot toddy would you like? \n";
            cout <<"( 1 cup - $2.20)\n";
            
            cin >> hot_toddy;
    
    
            cout << "That would be $" << calculator(hot_toddy, 2.20) << ".\n";
            break;
    
    
        case 2:
            cout << "How many cup of irish coffee would you like? \n";
    
    
            cin >> irish_coffee;
    
    
            cout << "That would be $" << calculator(irish_coffee, 2.00) << ".\n";
            break;
    
    
        case 3:
            cout << "How many cup of bishop would you like? \n";
            cout << "( 1 cup - 3.00 ) \n";
    
    
            cin >> bishop;
    
    
            cout << "That would be $" << calculator(bishop, 3.00) << ".\n";
            break;
    
    
        case 4:
            cout << "How many cup of cocoa would you like? \n";
            cout << "( 1 cup - $2.50 ) \n";
            
            cin >> cocoa;
    
    
            cout << "That would be $" << calculator(cocoa, 2.50 ) << ".\n";
            break;
    
    
        case 5:
            cout << "How many cup of tea would you like? \n";
            cout << " ( 1 cup - $ 1.20 ) \n";
    
    
            cin >> tea;
    
    
            cout << "That would be $" << calculator(tea,1.20) << ".\n";
            break;
    
    
        default:
            cout << "Invalid choice. See above. \n";
        }
    
    
        return hotdrinks;
    }
    
    
    int colddrinks()
    {
        int colddrinks;
        int iced_lemon_tea;
        int iced_milo;
        int lemon_juice;
        int apple_juice;
        int orange_juice;
    
    
        cout << "Please choose the cold drink you would like to order. \n";
        cout << "1. Iced lemon tea \n";
        cout << "2. Iced milo \n";
        cout << "3. Lemon juice \n";
        cout << "4. Apple juice \n";
        cout << "5. Orange juice \n";
        
        cin >> colddrinks;
        
        switch (colddrinks)
        {
        case 1:
            cout <<"How many cup of hot toddy would you like? \n";
            cout <<"( 1 cup - $2.20)\n";
            
            cin >> iced_lemon_tea;
    
    
            cout << "That would be $" << calculator(iced_lemon_tea, 2.20) << ".\n";
            break;
    
    
        case 2:
            cout << "How many cup of irish coffee would you like? \n";
    
    
            cin >> iced_milo;
    
    
            cout << "That would be $" << calculator(iced_milo, 2.00) << ".\n";
            break;
    
    
        case 3:
            cout << "How many cup of bishop would you like? \n";
            cout << "( 1 cup - 3.00 ) \n";
    
    
            cin >> lemon_juice;
    
    
            cout << "That would be $" << calculator(lemon_juice, 3.00) << ".\n";
            break;
    
    
        case 4:
            cout << "How many cup of cocoa would you like? \n";
            cout << "( 1 cup - $2.50 ) \n";
            
            cin >> apple_juice;
    
    
            cout << "That would be $" << calculator(apple_juice, 2.50 ) << ".\n";
            break;
    
    
        case 5:
            cout << "How many cup of tea would you like? \n";
            cout << " ( 1 cup - $ 1.20 ) \n";
    
    
            cin >> orange_juice;
    
    
            cout << "That would be $" << calculator(orange_juice,1.20) << ".\n";
            break;
    
    
        default:
            cout << "Invalid choice. See above. \n";
        }
    
    
        return colddrinks;
    
    
    }
    These are the errors (or warnings?) I get:

    1>------ Build started: Project: Food menu program, Configuration: Debug Win32 ------

    1> food menu program.cpp

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(8): warning C4067: unexpected tokens following preprocessor directive - expected a newline

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(9): warning C4067: unexpected tokens following preprocessor directive - expected a newline

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(136): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(200): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(300): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(335): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>c:\users\user\documents\visual studio 2010\projects\food menu program\food menu program\food menu program.cpp(371): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>c:\users\user\documents\visual studio 2010\projects\food menu
    program\food menu program\food menu program.cpp(406): warning C4305: 'argument' : truncation from 'double' to 'float'

    1>food menu program.obj : error LNK2019: unresolved external symbol "int __cdecl food(void)" (?food@@YAHXZ) referenced in function _main

    1>C:\Users\user\Documents\Visual Studio 2010\Projects\Food menu program\Debug\Food menu program.exe : fatal error LNK1120: 1 unresolved externals

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Thank you

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The first two warnings are about semi-colons at the end of the #include directives.

    The various warnings are about calls of calculator(). The definition of calculator() specifies that the second argument is of type float. In the statement, for example, "calculator( potato_chips, 2.50 )" the literal value 2.50 is of type double, which needs to be truncated to pass it to a function expecting a float. Change the "2.50" to "2.50f" to cure that warning. Similar approach with other warnings.



    You might want to compare the definition of food(), which starts with
    Code:
    int food (int westernfood(), int easternfood())
    with how it is previously declared
    Code:
    int food();
    The two do not align. You have effectively declared one version of food() - taking no arguments - and defined another which accepts two arguments. In C++, that achieves function overloading. The one declared with no arguments is not defined. Within main(), your code calls the version with no arguments. Which has not been defined, so the linker cannot resolve the call. To solve that, you need to make the declarations and definitions align (i.e. if you want to call the food() with no arguments, make sure you implement a version of food() with no arguments.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > I've finished the coding for the exercise
    Please don't tell me you wrote 500 lines of code without ever pressing "compile"?

    A development process
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    Thanks man
    You've been a doing me a huge favor!

    About the truncation warnings, what I did was changing the calculator type and price type to double. Does this have any consequence? Should I instead do what you told me?


    Again, thanks in advance.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    no I didn't... why? :/

  6. #6
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    I mean I did but still got error. Ignore it anyway until I finish it, so I can ask here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-13-2010, 10:02 PM
  2. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  3. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM
  4. Compiler error or human error?
    By skyruler54 in forum C++ Programming
    Replies: 6
    Last Post: 09-06-2002, 02:27 PM
  5. fatal error C1001: INTERNAL COMPILER ERROR
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-21-2002, 12:07 PM