I/O Functions Not Compiling...

This is a discussion on I/O Functions Not Compiling... within the C++ Programming forums, part of the General Programming Boards category; a little help needed with my functions which im using to save a structured array. i have the function prototypes ...

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

    I/O Functions Not Compiling...

    a little help needed with my functions which im using to save a structured array. i have the function prototypes at the begining, which are giving me the first set of error messages.

    i have put the functions at the bottom of the source file.

    if anybody could give me the answer as to why it wont compile will be perfect. thanks,

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <stdio.h>
    #include <fstream>
    
    using namespace std;
    
    struct Part   //decleration of data structure for parts
    {
        int Part_ID;
        char Description[15];
        char Condition[10];
        float Guide_Price;
        int Origin_Vehicle_ID;
        bool Present;
    };
    
    struct Vehicles //decleration of data structure for vehicles
    {
        int Vehicle_ID;
        char Model[10];
        char Colour[10];
        int Mileage;
        float Purchase_Price;
        Part Parts[323];
    };
    
    struct Order  //decleration of data structure for orders
    {
        int Order_ID;
        int Customer_ID;
        int Part_ID[10];
        bool Paid;
    };
    
    struct Customers  //decleration of data structure for customers details
    {
           int Customer_ID;
           char Name[15];
           char Address[15];
           char Addresstwo[15];
           char Town[10];
           char County[10];
           char Postcode[6];
           char TelNo[12];
           Order Orders[10];
    };
    
    
    int Program;
    int Number_of_Vehicles = 0, Number_of_Customers = 0;
    
    Customers Customer[10]; //arrayed data structures
    Vehicles Vehicle[10];
    
    int Show_Main_Menu();    //function prototypes
    void Get_Order_Quote();
    void Input_New_Customer();
    void Check_Order_Details();
    void Look_Up_Customer();
    void Place_New_Order();
    void Enter_New_Vehicle();
    int SaveVehicles(Vehicle*, int);
    int SaveCustomers(Customers*, int);
    int MasterFile(int, int);
    
    int main(int argc, char *argv[])
    {
    
        while(Program != 8)
        {//while 'program'
    
        switch (Show_Main_Menu())
        { //switch
    
    //------------------------------------------------------------------------------
        case 1:
        {//case 1
    
         Get_Order_Quote();
         break;
    
        }//case 1
    //------------------------------------------------------------------------------
        case 2:
        {//case 2
         
         Place_New_Order();
         break;
         
        }//case 2
    //------------------------------------------------------------------------------
        case 3:
        {//case 3
    
        Check_Order_Details();
        break;
    
        }//case 3
    //------------------------------------------------------------------------------
    
        case 4:
        {//case 4
    
          Input_New_Customer();
          SaveCustomers();
          break;
    
        }//case 4
    //------------------------------------------------------------------------------
    
       case 5:
        {//case 5
        
        cout << "Print Bills" << endl;
        break;
        
        }//case 5
    //------------------------------------------------------------------------------
        case 6:
        {//case 6
    
         Look_Up_Customer();
         break;
           
        }//case 6    
    //------------------------------------------------------------------------------
        case 7:
        {//case 7
        
        Enter_New_Vehicle();
        SaveVehicles(Number_of_Vehicles);
        break;
        
        }//case 7
    //------------------------------------------------------------------------------
        case 8:
        {//case 7
        
        return 0;    
        break;
        
        }//case 7
    //------------------------------------------------------------------------------
    }//switch statement   
    
    }//while 'program'
    
    }//int main
    
    //XXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    int Show_Main_Menu()                //OK and tested!
    {
        int Main_Menu_Option;
        system("cls");
        cout << " ** Main Menu **" << endl;
        cout << endl;
        cout << "1) Order Quote" << endl;
        cout << "2) New Order" << endl;
        cout << "3) Check Order Details" << endl;
        cout << "4) Enter New Customer" << endl;
        cout << "5) Print Bills" << endl;
        cout << "6) Look Up Customer" << endl;
        cout << "7) Enter New Vehicle" << endl;
        cout << "8) Quit Program" << endl;
        cout << endl;
        cout << "Option : ";
        cin >> Main_Menu_Option;
        system("cls");
        return Main_Menu_Option;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Input_New_Customer()    //looks OK but not tested!
    {
        system("cls");
        cout << "Enter New Customer" << endl;
        cout << endl;
        cout << "Name             : ";
        cin >> Customer[Number_of_Customers].Name;
        cout << "Address          : ";
        cin >> Customer[Number_of_Customers].Address;
        cout << "Address line two : ";
        cin >> Customer[Number_of_Customers].Addresstwo;
        cout << "Town             : ";
        cin >> Customer[Number_of_Customers].Town;
        cout << "County           : ";
        cin >> Customer[Number_of_Customers].County;
        cout << "Postcode         : ";
        cin >> Customer[Number_of_Customers].Postcode;    
        cout << "Customer ID      : " << Number_of_Customers << endl;
        cout << endl;
        Number_of_Customers ++;
        system("PAUSE");
        system("cls");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Check_Order_Details()      //Looks OK but not tested!
    {
        int Order_ID, i, x, y;
        
        system("cls");
        cout << "Check Order Details" << endl;
        cout << endl;
        cout << "Enter Order ID  : ";
        cin >> Order_ID;
    
        for(i=0; i<Number_of_Customers; i++)     //loops through all customers
        {
                 for(x=0; x<10; x++)   //loops through all orders that customer has
                 {
                   if(Customer[i].Orders[x].Order_ID == Order_ID) //checks each order for a match on Order_ID
                   {//if statement
                        cout << Customer[i].Orders[x].Part_ID << endl;     //displays details of the order
                        cout << Customer[i].Orders[x].Paid << endl;
                        cout << Customer[i].Orders[x].Customer_ID << endl;
                        
                        for(y=0; y<Number_of_Customers; y++) //loops through all customers
                        {//for loop
                                
                   if(Customer[y].Customer_ID == Customer[i].Orders[x].Customer_ID) //checks for match on Customers ID
                                 {//if statement
                                     cout << Customer[y].Name << endl; //displays name of customer above
                                     }//if statement
                        }//for loop
                        
                   }//if statement
                  }//for loop x
        }//for loop i
    
        cout << endl;
        system("PAUSE");
    
    };//function
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    void Get_Order_Quote()  //OK but not tested!
    {
         int ID, Part_ID, i;
         
         cout << "Order Quote" << endl;
         cout << endl;
         cout << "Input Part ID : ";
         cin >> ID;
    
    
         for(i=0; i<Number_of_Vehicles; i++)      //loops through all vehicles catalogued
         {//for loop ID
            for(ID=0; ID<323; ID++)    //loops through parts available on vehicle
    
            { //for loop i
    
       if(ID == Vehicle[i].Parts[ID].Part_ID && Vehicle[i].Parts[ID].Present == 1 )//checks for a match on the parts ID
               {//if
                   cout << Vehicle[i].Parts[ID].Part_ID << " is on Vehicle " << i << endl;
                   cout << Vehicle[i].Parts[ID].Description << " is " << Vehicle[i].Parts[ID].Guide_Price << endl;
                }//if
    
            }//for loop i
         }//for loop
    
     system("PAUSE");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Place_New_Order()
    {//func place_new_order
    
        int Sub_Opt, Customer_ID, Part_ID;
        int x, i;
        
        cout << "New Order" << endl;
        cout << endl;
        cout << "1) Create New Customer" << endl;
        cout << "2) Enter Customer ID" << endl;
        cout << endl;
        cout << "Option   : ";
        cin >> Sub_Opt;
    
        switch(Sub_Opt)
        {//switch subopt
    //------------------------------------------------------------------------------
        case 1:
        {//case 1
    
        Input_New_Customer();
        SaveCustomers(Number_of_Customers);
        break;
    
        }//case 1
    //------------------------------------------------------------------------------
        case 2:
        {//case 2
    
        cout << "Customer ID : ";
        cin >> Customer_ID;
        cout << "Enter Part ID";
        cin >> Part_ID;
        
        for(i=0; i<Number_of_Vehicles; i++)//loops through all vehicles
        {//for loop i
    
               for(x=0; x<323; x++)//loops through all parts in specific vehicle
               {//for loop x
    
             if(Part_ID == Vehicle[i].Parts[x].Part_ID && Vehicle[i].Parts[x].Present == 1)//test for a match of part_id and that its present on vehicle
    
                        {//if statement
    
                                   cout << Vehicle[i].Parts[x].Description << endl;
    
                                   }//if statement
                        }//for loop x
             }//for loop i
             
        break;
        }//case 2
    //------------------------------------------------------------------------------
    }//switch subopt
    };//func place_new_order
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Look_Up_Customer()        //OK and tested!
    {
            int ID;
            
            cout << "Look up Customer" << endl;
            cout << endl;
            cout << "Please Enter Customer ID : ";
            cin >> ID;
        
                cout << "Name      : " << Customer[ID].Name << endl;
                cout << "Address   : " << Customer[ID].Address << endl;
                cout << "            " << Customer[ID].Addresstwo << endl;
                cout << "            " << Customer[ID].Town << endl;;
                cout << "            " << Customer[ID].County << endl;                   
                cout << "            " << Customer[ID].Postcode << endl;
                cout << "Telephone : " << Customer[ID].TelNo << endl;
                system("PAUSE");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Enter_New_Vehicle()
    {//func Enter_New_Vehicle
          int i, Part_ID;
          
          cout << "Enter New Vehicle For Breaking" << endl;
          cout << endl;
          cout << "Model          : ";
          cin >> Vehicle[Number_of_Vehicles].Model;
          cout << "Colour         : ";
          cin >> Vehicle[Number_of_Vehicles].Colour;
          cout << "Mileage        : ";
          cin >> Vehicle[Number_of_Vehicles].Mileage;
          cout << "Purchase Price : ";
          cin >> Vehicle[Number_of_Vehicles].Purchase_Price;
          cout << "Vehicle ID     : " << Number_of_Vehicles << endl;
          
          for(i=0; i<323; i++)
          {
          Vehicle[Number_of_Vehicles].Parts[i].Present = 1;
          }
    
         cout << "What Parts Are Missing or Damaged?" << endl;
         cout << endl;
         cout << "Enter 8 When Finished" << endl;
         cout << endl;
         cout << "Part ID('s) Which are Missing or Damaged : ";
         cin >> Part_ID;
         
         if(Part_ID != 8)
         {//if statment 
                    
         for(i=0; i<323; i++)
         {//for loop
         if(Vehicle[Number_of_Vehicles].Parts[i].Part_ID == Part_ID)
         {//if statment
            Vehicle[Number_of_Vehicles].Parts[i].Present == 0;
            }//if statement
            }//for loop
         }//if statement
    
         Number_of_Vehicles++;
    
    };//func Enter_New_Vehicle
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    int SaveVehicles(Vehicle* Vehicles, int Number_of_Vehicles)
    {
            int i, x;
    
            ofstream Vehicle_File("d:\\Vehicle.dat");
    
            for(x=0; x<Number_of_Vehicles; x++)
            {//for loop x
    
            Vehicle_File << Vehicle[Number_of_Vehicles].Vehicle_ID << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Model << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Mileage << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Colour << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Purchase_Price << endl;
    
            for(i=0; i<323; i++)
            {//for loop i
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Part_ID << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Description << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Condition << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Guide_Price << endl;
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Origin_Vehicle_ID;
            Vehicle_File << Vehicle[Number_of_Vehicles].Parts[i].Present << endl;
            }//for loop i
    
            }//for loop x
            Vehicle_File.close();
            return 0;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    int SaveCustomers(Customers* Customer, int Number_of_Customers)
    {
            int i, x;
    
            ofstream Customers_File("d:\\Customers.dat");
    
            for(x=0; x<Number_of_Customers; x++)
            {//for loop x
    
            Customers_File << Customers[Number_of_Customers].Customer_ID << endl;
            Customers_File << Customers[Number_of_Customers].Name << endl;
            Customers_File << Customers[Number_of_Customers].Address << endl;
            Customers_File << Customers[Number_of_Customers].Addresstwo << endl;
            Customers_File << Customers[Number_of_Customers].Town << endl;
            Customers_File << Customers[Number_of_Customers].County << endl;
            Customers_File << Customers[Number_of_Customers].Postcode << endl;
            Customers_File << Customers[Number_of_Customers].TelNo << endl;
    
            for(i=0; i<10; i++)
            {//for loop i
            Customers_File << Customers[Number_of_Customers].Orders[i].Order_ID << endl;
            Customers_File << Customers[Number_of_Customers].Orders[i].Customer_ID << endl;
            Customers_File << Customers[Number_of_Customers].Orders[i].Part_ID << endl;
            Customers_File << Customers[Number_of_Customers].Orders[i].Paid << endl;
            }//for loop i
    
            }//for loop x
            Customers_File.close();
            return 0;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    int MasterFile(int Number_of_Vehicles, int Number_of_Customers)
    {
    
            ofstream Master_File("d:\\Master.dat");
    
            Master_File << Number_of_Vehicles << endl;
            Master_File << Number_of_Customers << endl;
    
            Master_File.close();
            return 0;
    };
    Last edited by dac; 11-12-2006 at 04:55 AM.

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    post your error messages. Then people can have a look and attempt to solve the problem
    I'm just trying to be a better person - My Name Is Earl

  3. #3
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by swgh
    post your error messages. Then people can have a look and attempt to solve the problem
    OK, sorry folks. never thought of that.

    65 E:\Computing Coursework.cpp expected primary-expression before ',' token
    65 E:\Computing Coursework.cpp expected primary-expression before "int"
    65 E:\Computing Coursework.cpp initializer expression list treated as compound expression
    E:\Computing Coursework.cpp In function `int main(int, char**)':

    theres a few more. but i think these are the main ones.
    Last edited by dac; 11-12-2006 at 04:56 AM.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Almost all of your errors are grammatical. In your SaveVehicles you spelled the class name wrong in your first argument, that causes subsequent errors in all calls to that function. In a few cases, you call your functions with the wrong number of arguments and in your SaveCustomers definition, you're using the wrong identifier for the object in each of your output statements. Customers is the class name, Customer is the object. This is why you shouldn't use similar identifiers. Also, in those statements, you're using the wrong variable as the subscript, look at your for loop, again.

    Lastly, in your preprocessor directives at the top, you use <stdio.h>, which like <stdlib.h> has a C++ equivalent <cstdio>
    Sent from my iPadŽ

  5. #5
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by SlyMaelstrom
    Almost all of your errors are grammatical. In your SaveVehicles you spelled the class name wrong in your first argument, that causes subsequent errors in all calls to that function. In a few cases, you call your functions with the wrong number of arguments and in your SaveCustomers definition, you're using the wrong identifier for the object in each of your output statements. Customers is the class name, Customer is the object. This is why you shouldn't use similar identifiers. Also, in those statements, you're using the wrong variable as the subscript, look at your for loop, again.

    Lastly, in your preprocessor directives at the top, you use <stdio.h>, which like <stdlib.h> has a C++ equivalent <cstdio>
    damn you guys are good. im aiming to be a programmer as a possible career choice, thanks for the help. ill amend it now. btw some of the errors may have been added as i was trying different things out. forgot to ctrl z them all before i pasted them on here.

  6. #6
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    ok, after much frustration ive decided to delete all the saving functions and start again with it. i have pasted them elsewhere for later reference.

    question: with the inputting functions say Input_New_Customer do they need to be passed the global variable Number_of_Customers? if so, wouldnt that make the function an int type? or is that just for the return type? in which case it would stay void.

    thanks,

  7. #7
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    scrub that. what an idiot i am. i declared the globally so any funtion can access them. durrr...

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    Compiling more often, say every 10 lines or so, will save you from say copy/pasting the same mistake all over the place, or accumulating so many problems that you can't cope when you eventually do decide to compile.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-26-2009, 12:21 AM
  2. Unkown Hang
    By Bladactania in forum C Programming
    Replies: 31
    Last Post: 04-22-2009, 10:33 AM
  3. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM
  4. File I/O Tutorial Not Compiling
    By oobootsy1 in forum C++ Programming
    Replies: 10
    Last Post: 03-08-2004, 12:24 PM
  5. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM

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