Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Can someone help me with my output (http://www.programmingforums.org/showthread.php?t=2518)

hopeolicious Feb 28th, 2005 4:47 PM

Can someone help me with my output
 
This is my source code and what is required is this:
make an inventory for four sodas (1though 4 as an id) and there must be an initial inventory gven before you start the programs which is menu driven
the menu gives you the ability of Enter inventory (like going in and redoing the inventory) Purchasing soda(adding to initial amount given in the inventory)
Selling soda (no explanation needed)
Display inventory(here either)
in it there are traps needed for
atempting to sell more than in inventory,
entering faulty letters for input(e,p,d,s, and q for quit are the only valid reads)
entering any negative numbers.

when I display my output i want it to consist of the brand id number and the amount puchased or sold and also the brand's name for each




:

#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;
}



All times are GMT -5. The time now is 4:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC