[#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
$

I don't know ANYTHING about C++ but I noticed a typo in this line "purchase(brand, quanitity, coke, pepsi, dry, hires);" there's an extra i in quantity.

"purchased" != "purchase"

>your code is crap
No argument there.

>haven you ever consider using header files and making it into objects
Using classes and objects isn't always the optimum solution, and for small programs, it may not be practical to use multiple files. I disagree with both of your reasons for calling the code crap.

>either you are stupid, or stupid
I hate to break it to you, but I'm not the one that seems stupid. :lol:

>but classes and object are always the best solution for any program
Prove it. Show me every program in existence and how objects are the best solution.

>the codes looks alot better
That's an opinion, and doesn't work well as an argument in favor of your preferred methodology.

>if you can make it work i will agreee with everything you said
If I can fix half a dozen typos, you'll agree with everything I said? Wow, you're a cheap date.

am sorry, just ignore me, but i am going to try and make the program work, thanks for being understanding

Narue Said:

Using classes and objects isn't always the optimum solution, and for small programs, it may not be practical to use multiple files. I disagree with both of your reasons for calling the code crap.

I agree, how about a struct instead of passing about 5 or 6 parameters. That way all you have to do is pass a single object.

Fix your typos too and your all set!

this is my new code but i keep getting errors in the purchase() and sell() i can input what i need but it doesnt do like the others and keep going until i quit the program

#include <iostream.h>
#include <stdlib.h>

int coke = 0, pepsi = 0, dry = 0, hires = 0, brand, squantity, x, y, quantity, totalcoke, totalpepsi, totaldry, totalhires, soldcoke, soldpepsi, solddry, soldhires, pcoke = 0, ppepsi = 0, pdry = 0, phires = 0, addcoke ,addpepsi, adddry, addhires, coke_add, pepsi_add, dry_add, hires_add;

void initialize();
void instructions();
void sale_type(char option);
void inventory(), purchased(),sell(), display_inventory(), quit();

void main()
{
     initialize();
     instructions();//call instructions function, say goodbye to main forever
}//end function

void initialize()
{
cout << "\n\n Please enter the amount of Coke cases: ";
cin.clear();
cin >> coke_add;
coke = coke_add;

cout << " Please enter the amount of Pepsi cases: ";
cin.clear();
cin >> pepsi_add;
pepsi = pepsi_add;

cout << " Please enter the amount of Canada Dry cases: ";
cin.clear();
cin >> dry_add;
dry = dry_add;

cout << " Please enter the amount of Hires cases: ";
cin.clear();
cin >> hires_add;
hires = hires_add;
}

void instructions()
{
     char option;//declare option variable, this will be used OVER AND OVER
     do
     {
          cout << "\n\nWhat would you like to do?\n";
          cout << " (E)nter Inventory\n";
          cout << " (P)urchase Soda\n";
          cout << " (S)old Soda\n";
          cout << " (D)isplay Inventory\n";
          cout << " (Q)uit\n";//print us some options
               cin  >> option;
               cin.ignore(80,'\n'); //take in an answer
          sale_type(option);//send that answer to sale_type!
     }while(option!='Q' && option!='q');//keep on keepin on till they pick exit!
     //end program
}//end function

void sale_type(char option)
{
     switch (option)//roll thru options
     {
          case 'E': case 'e':  //if they picked the number 1, its gonna go to this function,
                         //thats pretty much how the whole thing works
               inventory();
               break;
          case 'P': case 'p':
               purchased();
               break;
          case 'S': case 's':
               sell();
               break;
          case 'D': case 'd':
               display_inventory();
               break;
          case 'Q': case 'q':
               quit();
               break;
           default://THEY DIDNT READ THE MENU, WHO WOULD HAVE THOUGHT?!?!
               cout << "Please read and follow all directions\n";//if directions aren't followed
               break;
     }
}//end function

void inventory()
{
cout << "\n\n\n-------------------INVENTORY----------------" << endl;
cout << "\n\nPlease enter the inventory for each item "<< endl;
cout << "\nEnter the number of Coca-Cola cases: ";
cin >> addcoke;

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 >> addcoke;
   }
totalcoke = coke + addcoke;

cout << "\nEnter the number of Pepsi cases: ";
cin >> addpepsi;

while (cin.fail())
  {
        cin.clear();
        cin.ignore();
        cout << "Invalid input...please re-enter" << endl;
        cout << "\nEnter the number of Pepsi cases: " << endl;
        cin >> addpepsi;
    }
totalpepsi = pepsi + addpepsi;

cout << "\nEnter the number of Canada Dry cases: ";
cin >> adddry;

while (cin.fail())
   {
cin.clear();
        cin.ignore();
cout << "Invalid input...please re-enter" << endl;
        cout << "\nEnter the number of Canada Dry cases: " << endl;
        cin >> adddry;
   }
totaldry = dry + adddry;

cout << "\nEnter the number of Hires cases: ";
cin >> addhires;

while (cin.fail())
   {
        cin.clear();
        cin.ignore();
        cout << "Invalid input...please re-enter" << endl;
        cout << "\nEnter the number of Hires cases: " << endl;
        cin >> addhires;
   }
totalhires = hires + addhires;
//clearline();
}//end function

void purchased()
{
cout << "\n\n\n-------------Purchase Menu------------------" << endl;
cout << "\nBrand Identification numbers are as follow: " << endl;
cout << "1---Coca-Cola" << endl;
cout << "2---Pepsi" << endl;
cout << "3---Canada Dry" << endl;
cout << "4---Hires" << endl;
cout << "\nPlease enter the brand you would like to purchase: ";
cin >> x;
cout << "\nPlease enter the quantity of the brand you would like to purchase: ";
cin >> quantity;


while(x >= 1 && x <= 4)
  {
switch(x)
   {
case 1:
pcoke = quantity;
totalcoke = totalcoke + quantity;
cout << "Inventory updated..." << endl;
break;

case 2:
ppepsi = quantity;
totalpepsi = totalpepsi + quantity;
cout << "Inventory updated..." << endl;
break;

case 3:
pdry = quantity;
totaldry = totaldry + quantity;
cout << "Inventory updated..." << endl;
break;

case 4:
phires = quantity;
totalhires = totalhires + quantity;
cout << "Inventory updated..." << endl;
break;

default:
cout << "bbThe action you requested is invalid...nothing has been done..." << endl;
  }
 }
}//end function

void sell()
{
cout << "\n\n\n------------------Sell Menu-------------------------------" << endl;
cout << "\nPlease enter the brand id number you would like to sell: ";
cin >> y;
cout << "\nPlease enter the quantity of the brand you would like to sell: ";
cin >> quantity;

while (y >= 1 && y <= 4)
 {
switch(y)
 {
case 1:
soldcoke = squantity;
totalcoke = totalcoke - squantity;
while (!cin.fail() && quantity > 0)
  {
      if(squantity > coke)
        {
cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
         }
   }
        
cout << "Inventory updated...";
        break;

case 2:
soldpepsi = squantity;
totalpepsi = totalpepsi - squantity;
cin >> squantity;
while (!cin.fail() && squantity > 0)
 {
        if(squantity > pepsi)
         {
cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
          }
  }

         cout << "Inventory updated...";
         break;

case 3:
solddry = squantity;
totaldry = totaldry - squantity;
while (!cin.fail() && squantity > 0)
   {
       if(squantity > dry)
        {
cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
            }
   }
          cout << "Inventory updated...";
          break;

case 4:
soldhires = squantity;
totalhires = totalhires - squantity;
while (!cin.fail() && squantity > 0)
   {
       if(squantity > hires)
        {
cout << "Insufficient inventory to fill sell order, nothing changed." << endl;
        }
    }
           cout << "Inventory updated...";
           break;
	
default:
cout  << "ccThe action you requested is invalid...nothing has been done" << endl;
    }
  }
}//end function

void display_inventory()
{
cout << "              Present inventory"<< endl;
cout << "    BRAND    ID  CASES TOTAL PURCHASED SOLD  " << endl;
cout << "      Coke-- 1 -- " << coke << "\t" << totalcoke << "\t" << pcoke << "\t-" << soldcoke << endl;
cout << "     Pepsi-- 2 -- " << pepsi << "\t" << totalpepsi << "\t" << ppepsi << "\t-" << soldpepsi << endl;
cout << "Canada Dry-- 3 -- " << dry << "\t" << totaldry << "\t" << pdry << "\t-" << solddry << endl;
cout << "     Hires-- 4 -- " << hires << "\t" << totalhires << "\t" << phires << "\t-" << soldhires << endl;
}//end function

void quit()
{
cout << "\nPlease have a nice day!!!" << endl;
}//end function

Look at the condition for your loops, then look at the body of the loops and see how the condition could never change. You've written a bunch of infinite loops.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.