Thread: error when tring to run program

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    error when tring to run program

    Code:
    [#include <iostream.h>
    
    void initialize(int& coke, int& pepsi, int& dry, int& hires);
    void sales_type(char& sale_type, int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires);
    //void clearline();
    void purchased(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires);
    void sell(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires); 
    void display_inventory(int& coke, int& pepsi, int& dry, int& hires);
    
    
    int get_total_coke(int& coke, int& coke_add);
    int get_total_pepsi(int& _pepsi, int& pepsi_add);
    int get_total_dry(int& dry, int& dry_add);
    int get_total_hires(int& hires, int& hires_add);
    
    void main()
    {
    	       int coke = 0;
    	       int pepsi = 0;
               	       int dry = 0;
    	       int hires = 0;
    	       int brand;
    	       int quantity;	
    	       char sale_type;
    
    initalize(coke, pepsi, dry, hires);
    sales_type(s_type, brand, quantity, coke, pepsi, dry, hires);
    purchase(brand, quanitity, coke, pepsi, dry, hires);
    sell(brand, quantity, coke, pepsi, dry, hires);
    display_inventory(coke, pepsi, dry, hires);
    //clearline();
    }
    
    void initialize(int& coke, int& pepsi, int& dry, int& hires)
    {
           int coke_add;
           int pepsi_add;
           int dry_add;
           int hires_add;
    
    cout << "Please enter the inventory for each item "<< endl;
    cout << "Enter the number of Coca-Cola cases: ";
    cin >> coke_add;
    
    while (cin.fail())
      {
    cin.clear();
            cin.ignore(cin.fail());
            cout << "Invalid input...please re-enter"<< endl;
            cout << "\nEnter the number of Coca-Cola cases: ";
                  cin >> coke_add;
       }
    coke+= get_total_coke(coke, coke_add);
    
    cout << "\nEnter the number of Pepsi cases: ";
    cin >> pepsi_add;
    
    while (cin.fail())
      {
            cin.clear();
            cin.ignore();
            cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Pepsi cases: " << endl;
            cin >> pepsi_add;
        }
    pepsi+= get_total_pepsi( pepsi, pepsi_add);
    
    cout << "\nEnter the number of Canada Dry cases: ";
    cin >> dry_add;
    
    while (cin.fail())
       {
    cin.clear();
            cin.ignore();
    cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Canada Dry cases: " << endl;
            cin >> dry_add;
       }
    dry+= get_total_dry(dry, dry_add);
    
    cout << "\nEnter the number of Hires cases: ";
    cin >> hires_add;
    
    while (cin.fail())
       {
            cin.clear();
            cin.ignore();
            cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Hires cases: " << endl;
            cin >> hires_add;
       }
    hires+= get_total_hires(hires, hires_add);
    //clearline();
     }
    
    void sales_type(char& sale_type, int& brand, int& quantity, int& coke, int& pepsi,int& dry, int& hires)
    {
    cout << "\nPlease enter the command that you want to do: ";
    cin >> sale_type;
    cout << "\nPlease enter the brand that you would like to purchase: ";
    cin >> brand;
    cout << "\nPlease enter the quantity of the brand you would like to purchase: ";
    cin >> quantity;
    
    switch(sale_type)
    {
    case 'E': case 'e':
    initialize(coke, pepsi, dry, hires);
    break;
    
    case 'P': case 'p':
    purchased(brand, quantity, coke, pepsi, dry, hires);
    break;
    
    case 'S': case 's':
    sell(brand, quantity, coke, pepsi, dry, hires);
    break;
    
    case 'D': case 'd':
    display_inventory(coke, pepsi, dry, hires);
    break;
    
    case 'Q': case 'q':
    cout << "Thank you and have a nuce day!!!" << endl;
    break;
     }
    }
    
    void purchase(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires)
    {
    while(brand >= 1 && brand <= 4)
      {
    switch(brand)
       {
    case '1':
    coke = coke + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '2':
    pepsi = pepsi + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '3':
    dry = dry + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '4':
    hires = hires + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    default:
    cout << "bbThe action you requested is invalid.nothing has been done..." << endl;
      }
     }
    cin.clear();
    cin.ignore();
    cout << "\nThe action you requested is invalid.nothing has been done..." << endl;
    }
    
    void sell(int& brand, int& quantity,  int& coke, int& pepsi, int& dry, int& hires)
    {
    while (brand >= 1 && brand <= 4)
     {
    switch(brand)
     {
    case '1':
    while (!cin.fail() && quantity > 0)
            if(quantity > coke)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                 }
    else coke = coke - quantity;
            cout << "Inventory updated...";
            break;
    case '2':
    while (!cin.fail() && quantity > 0)
            if(quantity > pepsi)
             {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                  }
    else pepsi = pepsi - quantity;
             cout << "Inventory updated...";
             break;
    case '3':
    while (!cin.fail() && quantity > 0)
            if(quantity > dry)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                }
    else dry = dry - quantity;
              cout << "Inventory updated...";
              break;
    case '4':
    while (!cin.fail() && quantity > 0)
            if(quantity > hires)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                 }
    else hires = hires - quantity;
               cout << "Inventory updated...";
               break;
    
    default:
    cout  << "ccThe action you requested is invalid...nothing has been done" << endl;
         }
       }
    }
    
    int get_total_coke(int& coke, int& coke_add)
    {
    while (coke_add < 0)
      {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Coke cases: "<<endl;
    cin.clear();
    cin >> coke_add;
       }
     return coke_add;
    }
    
    int get_total_pepsi(int& pepsi, int& pepsi_add)
    {
    while (pepsi_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Pepsi cases: " << endl;
    cin.clear();
    cin >> pepsi_add;
       }
     return pepsi_add;
    }
    
    int get_total_dry(int& dry, int& dry_add)
    {
    while (dry_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Canada Dry cases: " << endl;
    cin.clear();
    cin >> dry_add;
       }
     return dry_add;
    }
    
    int get_total_hires(int& hires, int& hires_add)
    {
    while (hires_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Hires cases: " << endl;
    cin.clear();
    cin >> hires_add;
       }
     return hires_add;
    }
    
    void display_inventory(int& coke, int& pepsi, int& dry, int& hires)
    {
            cout << "Present inventory"<< endl;
            cout << "Coke--"<< coke << endl;
            cout << "Pepsi--"<< pepsi << endl;
            cout << "Canada Dry--" << dry << endl;
            cout << "Hires--" << hires << endl;
    }
    This is the error message i keep getting and i dont know what it means

    $ c++ 1.cpp
    Undefined first referenced
    symbol in file
    purchased(int &, int &, int &, int &, int &, int &)/var/tmp/ccYQ5XO1.o
    ld: fatal: Symbol referencing errors. No output written to a.out
    collect2: ld returned 1 exit status
    $

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Not sure if this is your problem or not, but it looks wrong:
    Code:
    switch(brand)
       {
    case '1':
    brand is an integer, but your case is for a char. Try this maybe:
    Code:
    switch(brand)
       {
    case 1:
    Try changing that for each case in your switch block. Do the same with the switch block inside the sell() function.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412

    Thumbs down

    ......Sir, that's a LOT of code to read through to spot one error....you can probably isolate the general area of the error yourself, so you don't really need to paste a thousand pages of code like that.

    Your compiler says the problem lies within your
    Code:
    purchased(int &, int &, int &, int &, int &, int &)
    function there.

    The problem is probably in the implementation of that function..but I can't even find it, and I searched for it throughout the 100000 lines of code you pasted. I used Ctrl+F to look for the implementation, and found nothing. I only see its declaration....and a call to it....

    I think I know your problem. Your declaration actually has the names of the parameters that you're passing in, but your implementation doesn't..? And You're making references to parameter names that you don't have defined in the implementation of your function...if you even wrote out the function at all. Or it just be defined in some other file...in which case you should've been enough of a sweetie-pie to go ahead and show us that too.

    Anyhoo, I'm gonna have to go ahead give you a bit of a thumbs down there for posting all that code to make people search through all one small little problem.
    Last edited by Krak; 02-28-2005 at 12:35 AM.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Listen to your compiler I found all of the errors by just compiling.
    Here is the fixed code with comments
    Code:
    #include <iostream>//This is the standard header
    using namespace std;
    
    void initialize(int& coke, int& pepsi, int& dry, int& hires);
    void sales_type(char& sale_type, int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires);
    //void clearline();
    void purchased(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires);
    void sell(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires); 
    void display_inventory(int& coke, int& pepsi, int& dry, int& hires);
    
    
    int get_total_coke(int& coke, int& coke_add);
    int get_total_pepsi(int& _pepsi, int& pepsi_add);
    int get_total_dry(int& dry, int& dry_add);
    int get_total_hires(int& hires, int& hires_add);
    
    int main()//main returns an int its never void
    {
    	       int coke = 0;
    	       int pepsi = 0;
               int dry = 0;
    	       int hires = 0;
    	       int brand;
    	       int quanitity;//another spelling error	
    	       char sale_type;
    
    initialize(coke, pepsi, dry, hires);//spelled function call wrong
    sales_type(sale_type, brand, quanitity, coke, pepsi, dry, hires);//spelling errors here
    purchased(brand, quanitity, coke, pepsi, dry, hires);//spelled function call wrong agian
    sell(brand, quanitity, coke, pepsi, dry, hires);//another spelling error(see a pattern?)
    display_inventory(coke, pepsi, dry, hires);
    //clearline();
    return 0;//need to return 0
    }
    
    void initialize(int& coke, int& pepsi, int& dry, int& hires)
    {
           int coke_add;
           int pepsi_add;
           int dry_add;
           int hires_add;
    
    cout << "Please enter the inventory for each item "<< endl;
    cout << "Enter the number of Coca-Cola cases: ";
    cin >> coke_add;
    
    while (cin.fail())
      {
    cin.clear();
            cin.ignore(cin.fail());
            cout << "Invalid input...please re-enter"<< endl;
            cout << "\nEnter the number of Coca-Cola cases: ";
                  cin >> coke_add;
       }
    coke+= get_total_coke(coke, coke_add);
    
    cout << "\nEnter the number of Pepsi cases: ";
    cin >> pepsi_add;
    
    while (cin.fail())
      {
            cin.clear();
            cin.ignore();
            cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Pepsi cases: " << endl;
            cin >> pepsi_add;
        }
    pepsi+= get_total_pepsi( pepsi, pepsi_add);
    
    cout << "\nEnter the number of Canada Dry cases: ";
    cin >> dry_add;
    
    while (cin.fail())
       {
    cin.clear();
            cin.ignore();
    cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Canada Dry cases: " << endl;
            cin >> dry_add;
       }
    dry+= get_total_dry(dry, dry_add);
    
    cout << "\nEnter the number of Hires cases: ";
    cin >> hires_add;
    
    while (cin.fail())
       {
            cin.clear();
            cin.ignore();
            cout << "Invalid input...please re-enter" << endl;
            cout << "\nEnter the number of Hires cases: " << endl;
            cin >> hires_add;
       }
    hires+= get_total_hires(hires, hires_add);
    //clearline();
     }
    
    void sales_type(char& sale_type, int& brand, int& quantity, int& coke, int& pepsi,int& dry, int& hires)
    {
    cout << "\nPlease enter the command that you want to do: ";
    cin >> sale_type;
    cout << "\nPlease enter the brand that you would like to purchase: ";
    cin >> brand;
    cout << "\nPlease enter the quantity of the brand you would like to purchase: ";
    cin >> quantity;
    
    switch(sale_type)
    {
    case 'E': case 'e':
    initialize(coke, pepsi, dry, hires);
    break;
    
    case 'P': case 'p':
    purchased(brand, quantity, coke, pepsi, dry, hires);
    break;
    
    case 'S': case 's':
    sell(brand, quantity, coke, pepsi, dry, hires);
    break;
    
    case 'D': case 'd':
    display_inventory(coke, pepsi, dry, hires);
    break;
    
    case 'Q': case 'q':
    cout << "Thank you and have a nuce day!!!" << endl;
    break;
     }
    }
    
    void purchased(int& brand, int& quantity, int& coke, int& pepsi, int& dry, int& hires)//spelled wrong
    {
    while(brand >= 1 && brand <= 4)
      {
    switch(brand)
       {
    case '1':
    coke = coke + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '2':
    pepsi = pepsi + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '3':
    dry = dry + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    case '4':
    hires = hires + quantity;
    cout << "Inventory updated..." << endl;
    break;
    
    default:
    cout << "bbThe action you requested is invalid.nothing has been done..." << endl;
      }
     }
    cin.clear();
    cin.ignore();
    cout << "\nThe action you requested is invalid.nothing has been done..." << endl;
    }
    
    void sell(int& brand, int& quantity,  int& coke, int& pepsi, int& dry, int& hires)
    {
    while (brand >= 1 && brand <= 4)
     {
    switch(brand)
     {
    case '1':
    while (!cin.fail() && quantity > 0)
            if(quantity > coke)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                 }
    else coke = coke - quantity;
            cout << "Inventory updated...";
            break;
    case '2':
    while (!cin.fail() && quantity > 0)
            if(quantity > pepsi)
             {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                  }
    else pepsi = pepsi - quantity;
             cout << "Inventory updated...";
             break;
    case '3':
    while (!cin.fail() && quantity > 0)
            if(quantity > dry)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                }
    else dry = dry - quantity;
              cout << "Inventory updated...";
              break;
    case '4':
    while (!cin.fail() && quantity > 0)
            if(quantity > hires)
            {
    cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
                 }
    else hires = hires - quantity;
               cout << "Inventory updated...";
               break;
    
    default:
    cout  << "ccThe action you requested is invalid...nothing has been done" << endl;
         }
       }
    }
    
    int get_total_coke(int& coke, int& coke_add)
    {
    while (coke_add < 0)
      {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Coke cases: "<<endl;
    cin.clear();
    cin >> coke_add;
       }
     return coke_add;
    }
    
    int get_total_pepsi(int& pepsi, int& pepsi_add)
    {
    while (pepsi_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Pepsi cases: " << endl;
    cin.clear();
    cin >> pepsi_add;
       }
     return pepsi_add;
    }
    
    int get_total_dry(int& dry, int& dry_add)
    {
    while (dry_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Canada Dry cases: " << endl;
    cin.clear();
    cin >> dry_add;
       }
     return dry_add;
    }
    
    int get_total_hires(int& hires, int& hires_add)
    {
    while (hires_add<0)
       {
    cout << " The action you have requested is invalid....nothing changed." << endl;
    cout << " Please enter the amount of Hires cases: " << endl;
    cin.clear();
    cin >> hires_add;
       }
     return hires_add;
    }
    
    void display_inventory(int& coke, int& pepsi, int& dry, int& hires)
    {
            cout << "Present inventory"<< endl;
            cout << "Coke--"<< coke << endl;
            cout << "Pepsi--"<< pepsi << endl;
            cout << "Canada Dry--" << dry << endl;
            cout << "Hires--" << hires << endl;
    }
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 07-11-2005, 03:07 AM
  5. plz help me run this program!!!
    By galmca in forum C Programming
    Replies: 8
    Last Post: 02-01-2005, 01:00 PM