A Function Calling a Function

This is a discussion on A Function Calling a Function within the C++ Programming forums, part of the General Programming Boards category; hi all again, i need one of my functions to call another function. im using references and prototypes, so i ...

  1. #1
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    A Function Calling a Function

    hi all again, i need one of my functions to call another function. im using references and prototypes, so i put all the references the function called needed in the function calling it. and obviously the prototype of the functin called within the calling function. however i get this error;

    E:\Computing Coursework\Computing Coursework.cpp In function `void Order_Quote(Vehicle_Struct*, int&, Customer_Struct*, int&, Order_Struct*, int&)':

    317 E:\Computing Coursework\Computing Coursework.cpp `Order_Part' cannot be used as a function

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Show us your code.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    and obviously the prototype of the functin called within the calling function
    prototype should be places before function calling other function, not within
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    prototype for called function;
    Code:
    void Order_Part(Customer_Struct*, int&, Order_Struct*, int&);
    prototype for function calling above;
    Code:
    void Order_Quote(Vehicle_Struct*, int&, Customer_Struct*, int&, Order_Struct*, int&);
    calling function;
    Code:
    void Order_Quote(Vehicle_Struct* Vehicles, int& Number_of_Vehicles, 
                                     Customer_Struct* Customers, int& Number_of_Customers, 
                                     Order_Struct* Orders, int& Number_of_Orders)
    {
         int Part_ID, i, x, y, Order_Part;
         char Buffer[10];
         char BufferPaid[10];
         
         cout << "Part ID      : ";
         
         cin.getline(Buffer, 10, '\n');
         Part_ID = atoi(Buffer);
    //----------------------------Order Quote---------------------------------------     
               for(x=1; x<=Number_of_Vehicles; x++)
               {//for loop x
                           
                  for(i=1; i<324; i++)
                  {//for loop i
                           
                           if(Vehicles[x].Parts[i].Part_ID == Part_ID)
                           {//if
                           system("cls");
                           cout << "Part ID            : " << Vehicles[x].Parts[i].Part_ID << endl;
                           cout << "Part Description   : " << Vehicles[x].Parts[i].Description << endl;
                           cout << "Condition          : " << Vehicles[x].Parts[i].Condition << endl;
                           cout << "Located on Vehicle : " << Vehicles[x].Parts[i].Origin_Vehicle_ID << endl;
                           
                                for(y=1; y<=Number_of_Vehicles; y++)
                                {//for loop y
                                        if(Vehicles[y].Vehicle_ID == Vehicles[x].Parts[i].Origin_Vehicle_ID)
                                         {//if statement
                                               cout << endl;
                                               cout << "Model              : " << Vehicles[y].Model << endl;
                                               cout << "Mileage            : " << Vehicles[y].Mileage << endl;
                                               cout << "Colour             : " << Vehicles[y].Colour << endl;
    
    //------------------------------------------------------------------------------
    Order_Part(Customers, Number_of_Customers, Orders, Number_of_Orders);     
    //------------------------------------------------------------------------------                               
                                                                                                                      
                        }//if statement                                                                     
                      }//for loop y                                                                 
                    }//if                                              
                  }//for loop i                      
                }//for loop x
                          
               
               cout << endl;                  
               system("PAUSE");                 
    }; //function
    called function;
    Code:
    void Order_Part(Customer_Struct* Customers, int& Number_of_Customers, 
                                     Order_Struct* Orders, int& Number_of_Orders)
    {//func place_new_order
                           
              char Buffer[10], BufferPaid[10];
              int Order_Part, Part_ID;     
                      
                           cout << endl;
                           cout << "Order This Part?  1) Yes (Customer ID Required), 2) Yes (New Customer), 3) No" << endl;
                           cout << endl;
                           
                           cin.getline(Buffer, 10, '\n');                      
                           Order_Part = atoi(Buffer);
                           
                           switch(Order_Part)
                           {//switch
    //------------------------------------------------------------------------------                       
                           case 1: 
                           {//case 1
                           cout << "Customer ID     : ";
                           cin.getline(Buffer, 10, '\n');
                           
                           cout << "Paid? 1) = Yes, 0) =  No ";
                           cin.getline(BufferPaid, 5, '\n');
                           
                           Orders[Number_of_Orders].Paid = atoi(BufferPaid);
                                                
                                                if(Orders[Number_of_Orders].Paid == 1)
                                                {//if statement
                                
                                                 cout << "Payment Method : " << endl;
                                
                                                 cin.getline(Orders[Number_of_Orders].Payment_Method, 15, '\n');                                            
                           
                                                  Orders[Number_of_Orders].Customer_ID = atoi(Buffer);
                                                  Orders[Number_of_Orders].Part_ID = Part_ID;
                                                      
                                                  }//if statement
                           
                           break;                       
                           }//case 1
    //------------------------------------------------------------------------------
                           case 2:
                           {//case 2
                           
                           //Input_New_Customer(Customers, Number_of_Customers);
                           break;
                           
                           }//case 2
    //------------------------------------------------------------------------------                       
                           case 3:
                           {//case 3
                           break;
                           }//case 3
                           }//switch
        
    
    };//func place_new_order
    theyre not finished, but i want them working before i go any further. cheers,

  5. #5
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by vart
    prototype should be places before function calling other function, not within
    it is posible to put a function prototype within another function and it will run once the prototype has been reached?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,267
    I'm guessing that the problem stems from the use of variable names that are the same as the function names.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by laserlight
    I'm guessing that the problem stems from the use of variable names that are the same as the function names.
    im an utter embarassment. please if any of you mods have a shred of decency youll delete this thread.

    thanks laserlight, for applying just 1/2 a brain cell to my problem and solving it.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Nice guess. This one's the culprit:
    int Order_Part,
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by CornedBee
    Nice guess. This one's the culprit:
    int Order_Part,
    [SARCASM] Really? [/SARCASM] lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  4. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM
  5. Calling a user-defined function in C++
    By brianptodd in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2002, 01:09 PM

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