Thread: //it shows "local function definitions are illegal" error. someone please help me.

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    1

    Unhappy //it shows "local function definitions are illegal" error. someone please help me.

    Code:
    #include <iostream.h>
    
    void showMenu();
    void showFees (double, int);
    
    
    void main()
    {
        int choice;
        int quantity=1;
    
        
    
    cout<<"\n\n\n";
    
    cout<<"         ====== WELCOME TO THE FAST RESTAURANT ORDER SYSTEM!======";
    cout<<"                    \t\t\t ---- Choose your order ----"<<endl<<endl;
    cout<<"  \t       1.Burger TipTop \t         2.Del Chicken"<<endl;
    cout<<"  \t       3.Chicken Fillet \t 4. Spaghetti "<<endl;
    cout<<"  \t       5.Coke           \t 6. Apple Pie"<<endl;
    
        char cust_name[50];
        cout<<"Please Enter Your Name:\t";
        cin.getline (cust_name,50);
    
        const int BurgerTipTopChoice = 1;
        const int DelChickenChoice = 2;
        const int ChickenFilletChoice = 3;
        const int SpaghettiChoice = 4;
        const int CokeChoice = 5;
        const int ApplePieChoice = 6;
        const int endOrderChoice = 7;
    
    
        const double BurgerTipTop = 6.00;
        const double DelChicken = 4.50;
        const double ChickenFillet = 3.75;
        const double Spaghetti = 5.50;
        const double Coke = 2.80;
        const double ApplePie = 3.20;
        
    
         do
        {
           
            showMenu();
            cin >> choice;
               
            while (choice < BurgerTipTopChoice || choice > endOrderChoice)
            {
                cout << "Please enter a valid menu choice: ";
                cin >> choice;
            }
       if (choice != endOrderChoice)
       {
    
    
    
        switch (choice)
                {
                    case BurgerTipTopChoice:
                        showFees(BurgerTipTop, quantity);
                        break;
                    case DelChickenChoice:
                        showFees(DelChicken, quantity);
                        break;
                    case ChickenFilletChoice:
                        showFees(ChickenFillet, quantity);
                        break;
                    case SpaghettiChoice:
                        showFees(Spaghetti, quantity);
                        break;
                    case CokeChoice:
                        showFees(Coke, quantity);
                        break;
                    case ApplePieChoice:
                        showFees(ApplePie, quantity);
                        break;
        }
       }
        }
    
       while (choice != endOrderChoice);
       
    }
    void showMenu()
    {
    
    
        cout << "\n\t\tHere our food available " << endl;
        cout << "1. Burger TipTop \tRM 6.00"<< endl;
        cout << "2. Del Chicken \t\tRM 4.50" << endl;
        cout << "3. Chicken Fillet   \tRM 3.75" << endl;
        cout << "4. Spaghetti \t\tRM 5.50" << endl;
        cout << "5. Coke \t\tRM 2.80" << endl;
        cout << "6. Apple Pie \t\tRM 3.20"<< endl;
        cout << "7. END ORDER" << endl;
        cout << "Please enter your menu choice: ";
    }
    
    void showFees(double itemCost, int quantity)
    {
        double amtcash;
        double totalBill = (itemCost * quantity);
        double amountDue=totalBill;
       
        cout << "Total Bill: RM" << totalBill << endl;
       
        cout << "Total Amount Due: RM" << amountDue << endl;
        cout << "Enter amount cash: RM";
        cin >> amtcash;
        double change = amtcash - amountDue;
        cout << "Change : RM" << change << endl;
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Does it give you a line number on which the error is occurring?

    On a side note, <iostream.h> is deprecated, and should not be used. use <iostream> instead. Note the lack of ".h" on the end.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Guest
    Guest
    Overall it looks ok to me. I know it sucks that this forum doesn't make it easy to paste tab indented code, but try properly indenting it regardless (your editor can probably convert tabs to space in a single command); it really helps other users in tracking down possible errors.

    The proper return type of main() is int, so definitely fix that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Local Function definitions are illegal
    By websaco in forum C++ Programming
    Replies: 7
    Last Post: 04-28-2014, 11:25 PM
  2. 5 times "local function definitions are illegal"
    By Borislav in forum C++ Programming
    Replies: 24
    Last Post: 01-11-2011, 02:37 AM
  3. Error: "illegal call of non-static member function"
    By Helix in forum Windows Programming
    Replies: 4
    Last Post: 12-31-2003, 10:01 PM
  4. 'Local Function Definitions are illegal' ?
    By kinghajj in forum C++ Programming
    Replies: 7
    Last Post: 11-10-2003, 08:35 PM
  5. Local function definitions are illegal error?
    By GrlNewB in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2003, 08:54 PM

Tags for this Thread