Solved

Getting quantity on hand requested to know quantity on hand keeping in mind reorderlevel for each part

Posted on 2004-04-21
37
287 Views
Last Modified: 2010-04-01
Hi,
Iam writing a code where a customer has to request parts, order qty required and update quantity on hand. I executes fine but doesn't do what it's supposed to do.
When it gets to how many of a specific part is required it loops and won't accept or update a qty on hand.
I will have to post my entire code so that you will see what appears on the screen. You will see I have more requirements that I have not completed as yet but I am just trying to get it to work step by step for the moment.

//PREPORCESSOR DIRECTIVES
#include <iostream>            //FOR CIN AND COUT
#include <iomanip>            //SETW
#include <cctype>            //FOR TOUPPER
#include <string>            //FOR STRING CLASS

using namespace std;      //REQUIRED WHEN USING IOSTREAM

//FUNCTION PROTOTYPES
bool AskForStart();
bool AskForCustomerID(int& CustomerId);
void Welcome (void);
void DisplayStock (int AxleStock, int BearingsStock, int BrakeStock);
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                                    int AxleStock, int BearingsStock, int BrakeStock);
float TotalCostParts(int AxleQty,int BearingsQty,int BrakeQty);
void DisplayInvoice ( int CustomerId, int AxleQty, int BearingsQty,
                               int BrakeQty);
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int&
                                BrakeStock,  int AxleQty, int BearingsQty, int BrakeQty);
void Reorder(int AxleStock,int BearingsStock,int BrakeStock);



int main()
{
      //DEFINE VARIABLES
      int AxleStock =0;            //AXLES IN STOCK
      int BearingsStock =0;      //BEARINGS IN STOCK
      int BrakeStock =0;            //BRAKES IN STOCK
      int AxleQty =0;
      int BearingsQty =0;
      int BrakeQty =0;
      string Part = " ";            //PART (GLOBAL)
      int QuantityOnHand =0;      //QUANTITY ON HAND (GLOBAL)
      double Price = 0.0;            //PRICE OF ITEM (GLOBAL)
      int reorderLevel =0;      //REORDER LEVEL
      int numberRequired =0;      //NUMBER OF PARTS REQUIRED
      int CustomerId=0;
      //CALL FUNCTIONS
      Welcome ();
      AskForStart();
      AskForCustomerID(CustomerId);
      DisplayStock (AxleStock,BearingsStock,BrakeStock);
      GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,AxleStock,BearingsStock,BrakeStock);
      UpdatePartsStock(AxleStock,BearingsStock,BrakeStock,AxleQty,BearingsQty,BrakeQty);
      TotalCostParts(AxleQty,BearingsQty,BrakeQty);
      DisplayInvoice(CustomerId,AxleQty,BearingsQty,BrakeQty);
      Reorder(AxleStock,BearingsStock,BrakeStock);
      return 0;
}//END main()
//--------------------------------------------------------------------------------------------
//THIS FUNCTION DISPLAYS A WELCOME MESSAGE THAT INCLUDES
//YOUR STUDENT NUMBER AND NAME
void Welcome (void)
{      
      string welcomeMessage ="Welcome to S0023838 Karen Stedman Spare Parts.";
      string supplying = "We supply parts for your vehicle. ";
      
      cout << welcomeMessage <<endl;
      cout << supplying <<endl<<endl<<endl;
}//END Welcome
//-------------------------------------------------------------------------------------------
bool AskForStart()
{
      char Reply = ' ';
      cout << "Are there any customers? (Y/N) => ";
      cin >> Reply;
      Reply = toupper(Reply);
      //IF WE DON'T HAVE A YES OR NO KEEP PROMPTING UNTIL WE DO
      while ((Reply !='N') && (Reply !='Y'))
      {
            cout << "ERROR:  Valid responses are 'Y' or 'N'." <<endl
                  << "Are there any customers? (Y/N) =>";
                  cin >> Reply;
            Reply = toupper(Reply);
      }//end while
      return (Reply == 'Y');
}      
//-----------------------------------------------------------------------
bool AskForCustomerID(int& CustomerId)
{
      cout << "Please enter your Customer ID (or -1 to quit) =>";
            cin>> CustomerId;

      while ((CustomerId != -1) && ((CustomerId < 1000) || (CustomerId > 9999)))
      {
            cout << "Customer ID has to be between 1000 and 9999." <<endl
                  << "Please enter Customer ID (or -1 to quit) =>";
                  cin >> CustomerId;
      }
      return (CustomerId != -1);
}
//-------------------------------------------------------------------------------------------

//THIS FUNCTION DISPLAYS A LIST OF THE ITEMS AVAILABLE, THEIR PRICES
//AND THE NUMBERS OF EACH ITEM THAT ARE AVAILABLE FOR SALE

void DisplayStock (int AxleStock, int BearingsStock, int BrakeStock)
{
      
      //DEFINE AND INITIALISE PART 1 OBJECTS AND VARIABLES
      int Code1 = 1;                                    //CODE PART 1
      string Part1 = "Axle";                  //PART REAR AXLE
      int QuantityOnHand1 =5;
      double Price1 = 128.00;                        //PRICE PART 1
      int reorderLevel1 = 2;                        //REORDER LEVEL PART 1
      
      //DEFINE AND INITIALISE PART 2 OBJECTS AND VARIABLES
      int Code2 = 2;                                    //CODE PART 2
      string Part2 = "Bearings";                  //PART BEARINGS
      int QuantityOnHand2 =20;
      double Price2 = 25.50;                        //PRICE PART 2
      int reorderLevel2 = 10;                        //REORDER LEVEL PART 2
      
      //DEFINE AND INITIALISE PART 3 OBJECTS AND VARIABLES
      int Code3 = 3;                                    //CODE PART 3
      string Part3 = "Brake Pads";            //PART BRAKE PADS
      int QuantityOnHand3 =12;
      double Price3 = 30.00;                        //PRICE PART 3
      int reorderLevel3 = 6;                        //REORDER LEVEL PART 3
      
      cout << "\nOur current stock is: " <<endl;
      
      //DISPLAY HEADINGS
      cout.precision(2);
      cout<< setw(4) <<"Code"
            << setw(8) <<"Part"
            << setw(24) <<"Quantity On Hand"
            << setw(8) <<"Price" << endl;
      
      //DISPLAY CURRENT STOCK
      cout.setf(ios::fixed);
      cout.setf(ios::showpoint);
      cout.precision(2);
      cout << setw(2) << Code1
            << setw(10) << Part1
            << setw(16) << QuantityOnHand1
            << setw(13) << "$ " <<Price1 << endl;
      
      cout << setw(2) << Code2
            << setw(14) << Part2
            << setw(13) << QuantityOnHand2
            << setw(13) << "$  " <<Price2 << endl;
      
      cout << setw(2) << Code3
            << setw(16) << Part3
            << setw(11) << QuantityOnHand3
            << setw(13) << "$  " <<Price3 << endl;
      
}//END Display Stock  
//---------------------------------------------------------------------
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                                    int AxleStock, int BearingsStock, int BrakeStock)
{
      int Code =0;                  //CODE
      int Integer =0;
      //THIS FUNCTION OBTAINS FROM THE USER THE ITEM CODE AND
      //THE QUANTITY OF EACH ITEM THAT ARE REQUIRED BY THE USER
      
      cout << "Enter the code for the part you want to buy => ";
      cin >> Code;
      
      while ((Code < 1) || (Code > 3))
      {
            cout << "Code must be in the range of 1 to 3." << endl
                  << "Enter the code for the part you want to buy => ";
            cin >> Code;
      }  !!!!! IT WORKS FINE TO THIS POINT AND I KNOW THAT MY WHILE STATEMENT IS NOT CORRECT BUT I'M NOT SURE HOW TO GET IT TO KNOW QTY ON HAND AND UPDATE AS IT'S ORDERED WHILE KEEPING IN MIND REORDER LEVELS.
      
      cout << "How many of this part would you like => ";
      cin >> Integer;
      
      while ((Integer !=1) || (Integer !=2) || (Integer !=3)) THIS PART HERE!!!
      {
            cout << "ERROR:  You must enter number required ==> ";
            cin >> Integer;            // try again
      }
      cout << "How many of this part would you like => ";
      cin >> Integer;

}//END GetOrderQuantities

void Clear(void)                        // clear standard input to end of line
{
      char Char = ' ';
      while (Char != '\n')
      {
            cin.get(Char);
      }
      
      char prompt;                        //prompt for more parts
      do {
            
            cout << "Would you like to buy more parts? (y/N)";
            cin >> prompt;
            
      }while (toupper(prompt) == 'Y');      // while answer Y loop otherwise end
}
//END Clear
//-----------------------------------------------------------------------

void DisplayInvoice ( int CustomerId, int AxleQty, int BearingsQty,
                               int BrakeQty)
{
      //THIS FUNCTION DISPLAYS THE INVOICE DETAILS
      
      string Part = " ";
      int Quantity =0;
      float Cost = 0.0;
      
      cout << "Invoice for Customer Number:" << CustomerId << endl;
      
      cout << "Part\tQuantity\tCost" <<endl;
      cout << "----\t--------\t----" <<endl;
      
      cout << Part << Quantity << Cost <<endl<<endl;

}//END DisplayInvoice

      //THIS FUNCTION CALCULATES AND RETURNS THE TOTAL COST OF THE ITEMS
      //THAT HAVE BEEN ORDERED      
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty)
{
      
      cout << " Total Cost of parts: $" << TotalCostParts <<endl;
      return 0;
}//END TotalCostParts
//--------------------------------------------------------------------
//THIS FUNCTION UPDATES THE QUANTITY OF EACH ELEMENT THAT REMAINS IN STOCK
//AFTER THE CUSTOMER IS SERVED
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int&
                                BrakeStock,
                                int AxleQty, int BearingsQty, int BrakeQty)
{                  
      int Code =0;
      int AxlesStock =0;
      int numberRequired =0;
      
      switch (Code)
      {
      case 1:      AxleQty = AxlesStock - numberRequired;
            break;
            
      case 2:      BearingsQty = BearingsStock - numberRequired;
            break;
            
      case 3:      BrakeQty = BrakeStock - numberRequired;
            break;
            
      case 4:      cout << "\nInvalid Code......Try again.";
      }//END switch
}//END UpdatePartsStock
//--------------------------------------------------------------------
//THIS FUNCTION DETERMINES WHICH ITEMS SHOULD BE REORDERED
void Reorder (int AxleStock, int BearingsStock, int BrakeStock)
{
      int QuantityOnHand =0,
            reorderLevel =0;
      
      if (QuantityOnHand < reorderLevel)
      {
            cout << "The following parts should be reordered: " <<endl;
      }
      else
      {
            cout << "No parts to be reordered at present. " << endl;
      }
}//END Reorder
/
0
Comment
Question by:KazIT
  • 21
  • 15
37 Comments
 

Author Comment

by:KazIT
ID: 10877451
I now also realise that somehow my program has to relate the code entered to the appropriate part ordered while also linking it to the qty on hand and the reorder level. But I'm not sure how to do this.

Kaz
0
 

Author Comment

by:KazIT
ID: 10877582
I have just now moved the function UpdatePartsStock to after functions GetOrderQuantities

Kaz
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10877646
Hi KazIT,
> //THIS FUNCTION DISPLAYS A WELCOME MESSAGE THAT INCLUDES
> //YOUR STUDENT NUMBER AND NAME

Homework detected... Switching to limited solution mode :-)

     int AxleStock =0;          //AXLES IN STOCK
     int BearingsStock =0;     //BEARINGS IN STOCK
     int BrakeStock =0;          //BRAKES IN STOCK
     int AxleQty =0;

You have written very "C-ish" code so far.

Imagine a system with 10000 parts. Do you really want to define 20000 variables? Probably not.
You also have a lot of redundant code this way.

So define a base class, such as StockItem. Axles, bearings and spare ashtrays are just instances of your StockItem class.

If you're familiar with the concept, use a factory pattern, which will also store the entire stock instances in a global place. This you can use later to iterate across your entire stock.

Same with customers. An order is a bit trickier. It's a list of item/quantity combinations which is also tied to a customer instance. As soon as an order is delivered, it should produce an invoice - which is an order with prices.

Cheers,
Stefan
0
 

Author Comment

by:KazIT
ID: 10877995
Hi Stefan,

I guess an assisgnment for a 1st level programming A course is the same as homework.  I don't know much about Classes and I haven't heard of the factory pattern so I will have to hit the books yet again I guess. Thanks for the hint at least.  :)

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10881050
I spotted this error:

>>>    while ((Integer !=1) || (Integer !=2) || (Integer !=3)) // THIS PART HERE!!!

That while loop will last for ever as any number is either not equal to 1 OR not equal to 2, ...

So change it to this:

     while ((Integer !=1) && (Integer !=2) && (Integer !=3)) // OK, now it's an AND condition


Regards, Alex



0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10881376
I made some changes to DisplayStock() and GetOrderQuantities(), mostly to transfer some data from one function to the next. If you overtake these functions, don't forget to change the prototypes also.

In DisplayStock() is changed arguments type from int to int&. So i could set the stock values in DisplayStock and have these values in GetOrderQuantities() also.

Note, you will need a function to read stock values from a file. That function must be called before DisplayStock. If you had such a function you could have argument type int in DisplayStock again.

In GetOrderQuantities() i use now stock values and return the quantity that has been bought. I use pointers to be able to handle all three parts using one variable.

Regards, Alex


void DisplayStock (int& AxleStock, int& BearingsStock, int& BrakeStock)
{
     
     //DEFINE AND INITIALISE PART 1 OBJECTS AND VARIABLES
     int Code1 = 1;                              //CODE PART 1
     string Part1 = "Axle";               //PART REAR AXLE
     AxleStock =5;
     double Price1 = 128.00;                    //PRICE PART 1
     int reorderLevel1 = 2;                    //REORDER LEVEL PART 1
     
     //DEFINE AND INITIALISE PART 2 OBJECTS AND VARIABLES
     int Code2 = 2;                              //CODE PART 2
     string Part2 = "Bearings";               //PART BEARINGS
     BearingsStock =20;
     double Price2 = 25.50;                    //PRICE PART 2
     int reorderLevel2 = 10;                    //REORDER LEVEL PART 2
     
     //DEFINE AND INITIALISE PART 3 OBJECTS AND VARIABLES
     int Code3 = 3;                              //CODE PART 3
     string Part3 = "Brake Pads";          //PART BRAKE PADS
     BrakeStock=12;
     double Price3 = 30.00;                    //PRICE PART 3
     int reorderLevel3 = 6;                    //REORDER LEVEL PART 3
     
     cout << "\nOur current stock is: " <<endl;
     
     //DISPLAY HEADINGS
     cout.precision(2);
     cout<< setw(4) <<"Code"
          << setw(8) <<"Part"
          << setw(24) <<"Quantity On Hand"
          << setw(8) <<"Price" << endl;
     
     //DISPLAY CURRENT STOCK
     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout.precision(2);
     cout << setw(2) << Code1
          << setw(10) << Part1
          << setw(16) << AxleStock
          << setw(13) << "$ " <<Price1 << endl;
     
     cout << setw(2) << Code2
          << setw(14) << Part2
          << setw(13) << BearingsStock
          << setw(13) << "$  " <<Price2 << endl;
     
     cout << setw(2) << Code3
          << setw(16) << Part3
          << setw(11) << BrakeStock
          << setw(13) << "$  " <<Price3 << endl;
     
}//END Display Stock  
//---------------------------------------------------------------------
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                              int AxleStock, int BearingsStock, int BrakeStock)
{
     int Code =0;               //CODE
     int Integer =0;
     //THIS FUNCTION OBTAINS FROM THE USER THE ITEM CODE AND
     //THE QUANTITY OF EACH ITEM THAT ARE REQUIRED BY THE USER
     
     cout << "Enter the code for the part you want to buy => ";
     cin >> Code;
     
     while ((Code < 1) || (Code > 3))
     {
          cout << "Code must be in the range of 1 to 3." << endl
               << "Enter the code for the part you want to buy => ";
          cin >> Code;
     }  // !!!!! IT WORKS FINE TO THIS POINT AND I KNOW THAT MY WHILE STATEMENT IS NOT CORRECT
        // BUT I'M NOT SURE HOW TO GET IT TO KNOW QTY ON HAND AND UPDATE AS IT'S ORDERED
        // WHILE KEEPING IN MIND REORDER LEVELS.
     
     int* pStock = NULL;
     int* pQty   = NULL;

     if (Code == 1)
     {
         pStock = &AxleStock;
         pQty   = &AxleQty;
     }
     else if (Code == 2)
     {
         pStock = &BearingsStock;
         pQty   = &BearingsQty;
     }
     else /* if (Code == 3) */
     {
         pStock = &BrakeStock;
         pQty   = &BrakeQty;
     }

     cout << "There are " << *pStock << " pieces to buy. " << endl;
     cout << "How many of this part would you like => ";
     cin >> Integer;
     
     while (Integer <= 0 || Integer > *pStock)  // THIS PART HERE!!!
     {
          cout << "ERROR:  You must enter a number in the range of 1 to " << *pStock << " ==> ";
          cin >> Integer;          // try again
     }

     *pQty = Integer;

}//END GetOrderQuantities



0
 

Author Comment

by:KazIT
ID: 10887611
Hi Alex,
Thankyou so much for explaining that to me.  
I just noticed that in the beginning where I ask "Are there any customers?(Y/N) "
my code doesn't take into consideration the No reply.  Do I need to put in there before the "return (Reply == 'Y');"
If (Reply=='Y')
{
// some how call on the function" AskForCustomerID"???
}
else if (Reply=='N')
{
cout << "\nOK, Bye then!" endl;
}
and one more question
seeing I need to get the TotalCostParts working properly will inserting
#include <math> enable me to work with a Total there?

Kaz
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 500 total points
ID: 10889570
>> my code doesn't take into consideration the No reply

That isn't quite correct as the Ask... functions already handle these quit codes correctly.


You may change your main() function like this:

int main()
{
    ...
     if (!AskForStart())
         return 1;
     if (!AskForCustomerID(CustomerId))
         return 2;
     ...
}

With that both entering 'N' in AskForStart() resp. '-1' in AskForCustomer()  successfully terminates the program. You may change the return type of all other functions where the user has to make inputs from void to bool accordingly and handle some input to quit also.

>> #include <math>

That isn't a standard include: you mean either <math.h> or <cmath>.

You need it only if you want to use floating point or math functions, e. g. sqrt, log10, atof,  or others.

That i couldn't see in the moment:

The function UpdatePartsStock() would work if you change it to this:

//THIS FUNCTION UPDATES THE QUANTITY OF EACH ELEMENT THAT REMAINS IN STOCK
//AFTER THE CUSTOMER IS SERVED
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int&
                           BrakeStock,
                           int AxleQty, int BearingsQty, int BrakeQty)
{    
     AxlesStock    -= AxleQty;  
     BearingsStock -= BearingsQty;
     BrakeStock    -= BrakeQty;
     }//END switch
}//END UpdatePartsStock
//--------------------------------------------------------------------


And you may easily implement TotalCostParts() by defining global variables AxlePrice, BearingsPrice, BrakePrice passing them analogue to the xxxQty parameters first to DisplayStock, where they got initializesd,  and finally to TotalCostParts. There you only need simple arithmetic functions that work without <cmath> functions.

Regards, Alex

BTW, tomorrow i'll show you an easy way to transfer all your functions and global variables to a class.


0
 

Author Comment

by:KazIT
ID: 10927225
Alex,
Is there a way to ask for "are there any customers" and "enter customerId without using functions.  Something like this

#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;

//FUNCTION PROTOTYPES
int GetIntegerResponse(int Lower, int Upper);
void ReadInteger(int &Integer);
void Clear(void);
void Welcome(void);
void DisplayStock(int AxleStock, int BearingsStock, int BrakeStock);
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                                    int AxleStock, int BearingsStock, int BrakeStock);
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int& BrakeStock,
                                int AxleQty, int BearingsQty, int BrakeQty);
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty);
void DisplayInvoice(int CustomerId, int AxleQty, int BearingsQty,
                              int BrakeQty);
void Reorder(int AxleStock, int BearingsStock, int BrakeStock);

int main()
{
      //DEFINE VARIABLES
      int AxleStock = 0;
      int BearingsStock =0;
      int BrakeStock =0;
      int AxleQty =0;
      int BearingsQty =0;
      int BrakeQty =0;
      int CustomerId =0;
      int Lower =1000;
      int Upper =9999;
      int Integer =0;
      char Reply = ' ';
      
      
      //CALL FUNCTIONS
      GetIntegerResponse(Lower,Upper);
      ReadInteger(Integer);
      Clear();
      Welcome();
      DisplayStock(AxleStock,BearingsStock,BrakeStock);
      GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,
            AxleStock, BearingsStock, BrakeStock);
      UpdatePartsStock(AxleStock, BearingsStock, BrakeStock,
            AxleQty,BearingsQty,BrakeQty);
      TotalCostParts(AxleQty, BearingsQty,BrakeQty);
      DisplayInvoice(CustomerId,AxleQty,BearingsQty,BrakeQty);
      Reorder(AxleStock,BearingsStock,BrakeStock);
      
      
      cout << "Are there any Customers? (Y/N) =>";
      cin >> Reply;
      Reply = toupper(Reply);
      
      while ((Reply != 'N') && (Reply != 'Y'))
      {
            cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
                  << "Are there any Customers? (Y/N) =>";
            cin >> Reply;
            Reply = toupper(Reply);
      }
      return (Reply == 'Y');
}//END main

int GetIntegerResponse(int Lower, int Upper)
{
            int Response;

cout << "Please enter your Customer ID =>";
cin >> Response;

      do
      {
            ReadInteger(Response);
            if (Response < Lower || Response > Upper)
            {
                  cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "      << Upper << "=> ";
            }
      }while (Response < Lower || Response > Upper);
      return Response;
}
void ReadInteger(int &Integer)
{
      cin >> Integer;
      while (cin.fail())
      {
            cin.clear();
            Clear();
            cout << "ERROR: You must enter a number => ";
            cin >> Integer;
      }
      Clear ();
}
void Clear(void)
{
      char Char = ' ';
      while (Char != '\n')
      {
            cin.get(Char);
      }
}
Iam supposed to only use the functions GetIntgerResponse, ReadInteger, and Clear

Kaz
0
 

Author Comment

by:KazIT
ID: 10927391
Can anyone answer my last question?

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10927522
You must not call functions. You may move all function code to that place where the function had been called before. So your sample code above will not work as you 'added' the questions at the end of main().

However, although functions are not absolutely necessary for your project it,  would be a bad fault to move functionality - the term 'functionality' already says it - from a sub function to the main function as the code couldn't be handled properly if not parted into smaller modules. The advantage of having a function is that it encapsulates a manageable unit of code and that it can be called more than once.

That isn't a C++ issue only as also in C programs main function normally has only a few calls or even only one call. If we go using classes and member functions instead of global functions, main() will look like this:

void main()
{
     Store store;
     store.run();
}

where all functionality from above will be called by Store::run() member function.

Regards, Alex
0
 

Author Comment

by:KazIT
ID: 10927636
Alex,
I do apologise for being a pest with this but my study so far has not covered Classes and member functions.

I have moved a couple of things around and gotten my code to appear how I need it to up until "Enter Customer ID"
It lets me enter the customer Id but then stops and wont move on to "Display Invoice" I'll show you what I have changed.
void main(void)
{
      //DEFINE VARIABLES
      int AxleStock = 0;
      int BearingsStock =0;
      int BrakeStock =0;
      int AxleQty =0;
      int BearingsQty =0;
      int BrakeQty =0;
      int CustomerId =0;
      int Lower =1000;
      int Upper =9999;
      int Integer =0;
      char Reply = ' ';
      
      
      //CALL FUNCTIONS
      Welcome();
      GetIntegerResponse(Lower,Upper);
      ReadInteger(Integer);
      Clear();
      DisplayStock(AxleStock,BearingsStock,BrakeStock);
      GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,
            AxleStock, BearingsStock, BrakeStock);
      UpdatePartsStock(AxleStock, BearingsStock, BrakeStock,
            AxleQty,BearingsQty,BrakeQty);
      DisplayInvoice(CustomerId,AxleQty,BearingsQty,BrakeQty);
      TotalCostParts(AxleQty, BearingsQty,BrakeQty);
      Reorder(AxleStock,BearingsStock,BrakeStock);
      
}//END main
void Welcome(void)
{
      string WelcomeMessage = "Welcome to S0023838 Karen Stedman Spare Parts.";
      string supplying = "We supply parts for your vehicle.";
      
      cout << WelcomeMessage << endl;
      cout << supplying << endl << endl;
      
      char Reply = ' ';
      
      cout << "Are there any Customers? (Y/N) =>";
      cin >> Reply;
      Reply = toupper(Reply);
      
      while ((Reply != 'N') && (Reply != 'Y')) !!CHECKS FOR Y OR N OK
      {
            cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
                  << "Are there any Customers? (Y/N) =>";
            cin >> Reply;
            Reply = toupper(Reply);
      }
}

int GetIntegerResponse(int Lower, int Upper)
{
      
      int Response;
      
      cout << "Please enter your Customer ID =>"; !!DOESN'T SEEM TO MOVE ON FROM HERE!!!!
      cin >> Response;
      
      do
      {
            ReadInteger(Response);

            if (Response < Lower || Response > Upper)
            {
                  cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                        << Upper << "=> ";
            }//END if
      }//END do/while
      while (Response < Lower || Response > Upper);
return Response;
}
void ReadInteger(int &Integer)
{
      cin >> Integer;
      while (cin.fail())
      {
            cin.clear();
            Clear();
            cout << "ERROR: You must enter a number => ";
            cin >> Integer;
      }
      Clear ();
}
void Clear(void)
{
      char Char = ' ';
      while (Char != '\n')
      {
            cin.get(Char);
      }
}
THE GETINTEGER RESPONSE, READINTEGER AND CLEAR ARE ALL FUNCTIONS I AM REQUIRED TO USE.
I do realise that there are better ways to write the code as you have said but I am limited to the information I have been requested to use.

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10927927
The problem is that you have two inputs, one with cin >> Response in GetIntegerResponse() and one in ReadInteger().

int GetIntegerResponse(int Lower, int Upper)
{
     
     int Response;
     
     cout << "Please enter your Customer ID =>"; !!DOESN'T SEEM TO MOVE ON FROM HERE!!!!
     cin >> Response;       // HERE YOU ALREADY GOT THE CUSTOMER-ID
     
     do
     {
          // HERE YOU TRY TO READ IT AGAIN
          // REMOVE THAT STATEMENT AND FUNCTION
          ReadInteger(Response);

          if (Response < Lower || Response > Upper)
          {
               cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                    << Upper << "=> ";
          }//END if
     }//END do/while
     while (Response < Lower || Response > Upper);
return Response;
}
void ReadInteger(int &Integer)
{
     cin >> Integer;
     while (cin.fail())
     {
          cin.clear();
          Clear();
          cout << "ERROR: You must enter a number => ";
          cin >> Integer;
     }
     Clear ();
}

So, you need this:

int GetIntegerResponse(int Lower, int Upper)
{
     int Response;    
     do
     {
          cout << "Please enter your Customer ID =>";
          cin >> Response;      

          if (Response < Lower || Response > Upper)
          {
               cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                    << Upper << "=> ";
          }//END if
     }//END do/while
     while (Response < Lower || Response > Upper);

    return Response;
}

Regards, Alex

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10928421
I would replace function GetIntegerResponse by that:
 
bool AskForCustomerID(int Lower, int Upper, int& CustomerId)
{
    int Response;
   
    do
    {
        cout << "Please enter your Customer ID [0 to quit] =>";
        cin >> Response;

        if (Response == 0)
            return false;
       
        if (Response < Lower || Response > Upper)
        {
            cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                << Upper << "=> ";
        }//END if
    }//END do/while
    while (Response < Lower || Response > Upper);
   
    CustomerId = Response;
    return true;
}

You did remember my comments that you always should give the user a chance to quit? You need a bool return for all functions having user inputs, e. g. function Welcome()

bool Welcome(void)
{
     string WelcomeMessage = "Welcome to S0023838 Karen Stedman Spare Parts.";
     string supplying = "We supply parts for your vehicle.";
     
     cout << WelcomeMessage << endl;
     cout << supplying << endl << endl;
     
     char Reply = ' ';
     
     cout << "Are there any Customers? (Y/N) =>";
     cin >> Reply;
     Reply = toupper(Reply);
     
     while ((Reply != 'N') && (Reply != 'Y')) !!CHECKS FOR Y OR N OK
     {
          cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
               << "Are there any Customers? (Y/N) =>";
          cin >> Reply;
          Reply = toupper(Reply);
     }

     return (Reply == 'Y');    // true if 'Y', false if 'N'
}


That functions would be called in main() like this

   void main()
   {
          ....
         if (!Welcome())
              return;             // exit function main()  if 'N' had been entered in Welcome()

         if (!AskForCustomerID(lower, upper, CustomerId))
              return;            // exit function main()  if 0 had been entered in AskForCustomerID        
         
         ....
   }


Not, in main() you should only call functions that make sense and you have to care for the order:

>> //CALL FUNCTIONS
>>     GetIntegerResponse(Lower,Upper);
>>     ReadInteger(Integer);
>>     Clear();
>>     Welcome();
     
That's nonsense!! You couldn't call functions ignoring any program logic.

 First say welcome, then ask for customer id, then display stock ... and always check if you get your variables properly set and moved from main to the functions and back where necessary ...

>> but my study so far has not covered Classes and member functions.

That is strange for a '1st level programming A course' in C++. Or is it a C course? Does that mean that you are not allowed to use classes?

Regards, Alex


0
 

Author Comment

by:KazIT
ID: 10928494
Thanks for that Alex the code continues to the next point fine.
Where I output the Total Cost of Parts it's printing
Total Cost of Parts:        $  0040133E instead of the Currency Output
this is what I have specified
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty)
//THIS FUNCTION CALCULATES AND RETURNS THE TOTAL COST OF THE ITEMS THAT HAVE BEEN ORDERED
{
      cout.setf(ios::fixed);
      cout.setf(ios::showpoint);
      cout.precision(2);
      
      cout <<setw(6)<<"Total Cost of parts:" <<"  $  "<<TotalCostParts<<endl;
      return 0;
}
I thought by adding the fixed, showpoint and precision it would fix this?

Kaz
0
 

Author Comment

by:KazIT
ID: 10928536
Alex,
It's a Visual C++ that I am learning incorporated in course named Programming A
Iam not to use bool for some reason. Only what is specified. eg Void

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10929157

TotalCostParts is the name of the function and handled here as a function pointer. '0040133E' is that pointer. You have to pass price info to function TotalCostParts and calculate the total amount of costs before outputting.

Add those variables to main():

     float AxlePrice =0.0;
     float BearingsPrice =0.0;
     float BrakePrice =0.0;

Pass them to DisplayStock similar to the *Stock arguments. Fill these variables with price info in DisplayStock and finally pass them to TotalCostParts() function.



float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty, int AxlePrice, int BearingsPrice, int BrakePrice)
//THIS FUNCTION CALCULATES AND RETURNS THE TOTAL COST OF THE ITEMS THAT HAVE BEEN ORDERED
{
     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout.precision(2);

     float totalCost = AxleQty * AxlePrice + BearingsQty * BearingsPrice + BrakeQty * BrakePrice;
     
     cout <<setw(6)<<"Total Cost of parts:" <<"  $  "<< totalCost <<endl;
     return totalCost;
}

Regards, Alex

 
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10929310
>> I am not to use bool for some reason

No classes, no bool ? It sound's like "Learning English not using verbs and adjectives".

Anyhow, you could quit program using exit(..) function, e. g.

#include <process.h>

...

void Welcome(void)
{
     string WelcomeMessage = "Welcome to S0023838 Karen Stedman Spare Parts.";
     string supplying = "We supply parts for your vehicle.";
     
     cout << WelcomeMessage << endl;
     cout << supplying << endl << endl;
     
     char Reply = ' ';
     
     cout << "Are there any Customers? (Y/N) =>";
     cin >> Reply;
     Reply = toupper(Reply);
     
     while ((Reply != 'N') && (Reply != 'Y')) !!CHECKS FOR Y OR N OK
     {
          cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
               << "Are there any Customers? (Y/N) =>";
          cin >> Reply;
          Reply = toupper(Reply);
     }

     if (Reply == 'N')
         exit(1);
}


Regards, Alex

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:KazIT
ID: 10937422
Thanks Alex my Y/N now works as it is intended to.
Question with regards to the Display Stock function.
Should I change my variable Price to a float or will double work fine in with everything else?

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10937496
I would suggest to use doubles as there are many operations that have a double as a result, so you would have to 'cast' if you assign double values to float variables.

So, replace all float's by double's and it's all easier.

Regards, Alex
 
0
 

Author Comment

by:KazIT
ID: 10938073
In regard to the total cost parts adding AxlePrice etc etc goes against what my function has been set as.  The variables in that function are only int AxleQty, int BearingsQty, int BrakeQty. I'm not allowed to alter it or any of the other function variables for that matter.  I'm sorry Alex but these are the only parameters I can work with.

I will write what my program has to output with examples to show you that I have to loop certain questions.

 Welcome to S0023838 Karen Stedman Spare Parts
We supply parts for you vehicle

Are there any customers? => y
Pleae enter your Customer ID => 1236
Our current stock is:
Code     Part        Quantity on Hand        Price
1          Axle                     5                  $ 128.00
2         Bearings               20                 $   25.50
3         Brake Pads            12                 $  30.00
Enter the code for the part you want to buy => 1
How many of this part would you like => 2
Would you like to buy more parts? => y
Enter the code for the part you want to buy => 2
How many of this part would you like => 10
Would you like to buy more parts? => n


Invoice for Customer Number:     1236

 Part                          Quantity        Cost
Axle                               2              $ 256.00
Bearings                       10              $ 255.00

Total Cost of parts:                         $ 511.00

Are there any more customers? => y
Please enter your Customer ID => 1789
Our current stock is:
Code          Part          Quantity on Hand               Price
1              Axle                     3                          $ 128.00
2             Bearings              10                          $  25.50
3             Brake Pade           12                         $  30.00
Enter the code for the part you want to buy => 2
How many of this part would you like => 12

ERROR: Number must be between 0 and 10 => 10
Would you like to buy more parts? => n

Invoice for Customer Number:        1789

 Part              Quantity             Cost
Bearings          10                    $ 255.00

Total Cost of parts:                  $ 255.00

Are there any more customers? => n

The following parts should be reordered:

Bearings

The predetermined reorder levels are Axle 2 Bearings 20 Brake Pads 6

I'm hoping this will explain easier what I am trying to achieve.

0
 

Author Comment

by:KazIT
ID: 10939146
I now have the TotalCostParts function working
Kaz

Alex,
If you have the time(and the inclination :) ) I would really like your thoughts on the second part of my question.

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10940384
I give you a new main() function that would do what you request - maybe by adopting a few of your functions...

Note, that you have to redo your last changes as i had an older version of main() here.


int main()
{
     //DEFINE VARIABLES
     int AxleStock =0;          //AXLES IN STOCK
     int BearingsStock =0;     //BEARINGS IN STOCK
     int BrakeStock =0;          //BRAKES IN STOCK
     int AxlePrice =0;          //AXLES IN PRICE
     int BearingsPrice =0;     //BEARINGS IN PRICE
     int BrakePrice =0;          //BRAKES IN PRICE
     int AxleQty =0;
     int BearingsQty =0;
     int BrakeQty =0;
     string Part = " ";          //PART (GLOBAL)
     int QuantityOnHand =0;     //QUANTITY ON HAND (GLOBAL)
     double Price = 0.0;          //PRICE OF ITEM (GLOBAL)
     int reorderLevel =0;     //REORDER LEVEL
     int numberRequired =0;     //NUMBER OF PARTS REQUIRED
     int CustomerId=0;

     char  c;
     char* pszAskCustomer = "Are there any customers? =>";

     //CALL FUNCTIONS

     Welcome ();      // Welcome only once
     while (true)
     {

         c = AskForStart();
         if (c == 'N')
             break;              // exit while loop

         AskForCustomerID(CustomerId, pszAskCustomer);

         while (true)
         {
             DisplayStock (AxleStock,BearingsStock,BrakeStock, AxlePrice,BearingsPrice,BrakePrice);
             GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,AxleStock,BearingsStock,BrakeStock);
             if (AxleQty == 0 && BearingsQty == 0 && BrakeQty == 0)
             {
                 cout << "Thank you for visiting. Bye." << endl;
                 break;   // exit inner while loop
             }
             UpdatePartsStock(AxleStock,BearingsStock,BrakeStock,AxleQty,BearingsQty,BrakeQty);
             TotalCostParts(AxleQty,BearingsQty,BrakeQty, AxlePrice,BearingsPrice,BrakePrice);
             DisplayInvoice(CustomerId,AxleQty,BearingsQty,BrakeQty, AxlePrice,BearingsPrice,BrakePrice);
             Reorder(AxleStock,BearingsStock,BrakeStock);
             // Init quantity variables
             AxleQty = BearingsQty = BrakeQty = 0;
         }

         // We need a different question if not initial
         pszAskCustomer = "Are there any more customers? =>";
     }
}//END main()

Regards, Alex
0
 

Author Comment

by:KazIT
ID: 10948271

Alex,
Once again I thankyou for the time and effort you are putting into this for me.

I have adjusted my code to only include the functions that I have been set.  Here is my amended code that executes as I have shown further down.  I have commented where I am having problems.

#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <process.h>
using namespace std;

//FUNCTION PROTOTYPES
void Welcome(void);
int GetIntegerResponse(int Lower, int Upper);
void DisplayStock(int& AxleStock, int& BearingsStock, int& BrakeStock);
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                                    int AxleStock, int BearingsStock, int BrakeStock);
void DisplayInvoice(int CustomerId, int AxleQty, int BearingsQty,
                              int BrakeQty, int AxleStock, int BearingsStock, int BrakeStock);
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty);
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int& BrakeStock,
                                int AxleQty, int BearingsQty, int BrakeQty);
void Reorder(int AxleStock, int BearingsStock, int BrakeStock);


void main(void)
{
      //DEFINE VARIABLES
      int AxleStock = 0;
      int BearingsStock =0;
      int BrakeStock =0;
      int AxleQty =0;
      int BearingsQty =0;
      int BrakeQty =0;
      int CustomerId =0;
      int Lower =1000;
      int Upper =9999;
      int Integer =0;
      char Reply = ' ';
      
      
      //CALL FUNCTIONS
      Welcome();
      GetIntegerResponse(Lower,Upper);
      DisplayStock(AxleStock,BearingsStock,BrakeStock);
      GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,
            AxleStock, BearingsStock, BrakeStock);
      DisplayInvoice(CustomerId,AxleQty,BearingsQty,BrakeQty,
                AxleStock,BearingsStock,BrakeStock);
      TotalCostParts(AxleQty,BearingsQty,BrakeQty);
      UpdatePartsStock(AxleStock, BearingsStock, BrakeStock,
      AxleQty,BearingsQty,BrakeQty);
      Reorder(AxleStock,BearingsStock,BrakeStock);
      
}//END main
//*******************************************************************************
//function : Welcome
//DISPLAYS A WELCOME MESSAGE THAT INCLUDES YOUR STUDENT NO AND NAME
//*******************************************************************************

void Welcome(void)
{
      cout << "Welcome to S0023838 Karen Stedman Spare Parts." << endl;
      cout << "We supply parts for your vehicle." << endl << endl;
      
      char Reply = ' ';
      
      cout << "Are there any Customers? (Y/N) =>";
      cin >> Reply;
      Reply = toupper(Reply);
      
      while ((Reply != 'N') && (Reply != 'Y'))
      {
            cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
                  << "Are there any Customers? (Y/N) =>";
            cin >> Reply;
            Reply = toupper(Reply);
      }
      if (Reply == 'N')
         exit(1);
}
//*******************************************************************************
//function : GetIntegerResponse
//GET AN INTEGER RESPONSE FROM THE USER IN THE RANGE LOWER .. UPPER
//*******************************************************************************

int GetIntegerResponse(int Lower, int Upper)
{
      int Response;
            
      do
      {
            cout <<"Please enter Customer ID =>";
            cin >>Response;

            if (Response < Lower || Response > Upper)//IF NOT IN THE RANGE LOWER ..UPPER
                  //PRINT ERROR MSG AND LOOP UNTIL RESPONSE IN THIS RANGE
            {
                  cerr << "\nERROR: Number must be between  " << Lower << " and "
                        << Upper <<endl;
            }//END if
      }//END do/while
      while (Response < Lower || Response > Upper);
      //RETURN THE USER'S SELECTION
return Response;
}
//********************************************************************************
//function : DisplayStock
//DISPLAYS A LIST OF THE ITEMS AVAILABLE, THEIR PRICES
//AND THE NUMBERS OF EACH ITEM THAT ARE AVAILABLE FOR SALE
//********************************************************************************

void DisplayStock(int& AxleStock, int& BearingsStock, int& BrakeStock)
{
  //DEFINE AND INITIALISE PART 1 OBJECTS AND VARIABLES
     int Code1 = 1;                              //CODE PART 1
     string Part1 = "Axle";               //PART REAR AXLE
     AxleStock =5;
     double AxlePrice = 128.00;                    //PRICE PART 1
     
     //DEFINE AND INITIALISE PART 2 OBJECTS AND VARIABLES
     int Code2 = 2;                              //CODE PART 2
     string Part2 = "Bearings";               //PART BEARINGS
     BearingsStock =20;
     double BearingsPrice = 25.50;                    //PRICE PART 2
     
     //DEFINE AND INITIALISE PART 3 OBJECTS AND VARIABLES
     int Code3 = 3;                              //CODE PART 3
     string Part3 = "Brake Pads";          //PART BRAKE PADS
     BrakeStock=12;
     double BrakePrice = 30.00;                    //PRICE PART 3
     
     cout << "Our current stock is: " <<endl;
     
     //DISPLAY HEADINGS
     cout.precision(2);
     cout<< setw(4) <<"Code"
          << setw(8) <<"Part"
          << setw(24) <<"Quantity On Hand"
          << setw(8) <<"Price" << endl;
     
     //DISPLAY CURRENT STOCK
     cout.setf(ios::fixed);
     cout.setf(ios::showpoint);
     cout.precision(2);
     cout << setw(2) << Code1
          << setw(10) << Part1
          << setw(16) << AxleStock
          << setw(13) << "$ " <<AxlePrice << endl;
     
     cout << setw(2) << Code2
          << setw(14) << Part2
          << setw(13) << BearingsStock
          << setw(13) << "$  " <<BearingsPrice << endl;
     
     cout << setw(2) << Code3
          << setw(16) << Part3
          << setw(11) << BrakeStock
          << setw(13) << "$  " <<BrakePrice << endl;
     
}//END Display Stock  
//****************************************************************************
//function : GetOrderQuantities
//OBTAINS FROM THE USER THE ITEM CODE AND THE QUANTITY OF EACH
//ITEM THAT ARE REQUIRED BY THE USER
//****************************************************************************

void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                                    int AxleStock, int BearingsStock, int BrakeStock)
{
      int Code =0;               //CODE
      int Integer =0;
      
      cout << "Enter the code for the part you want to buy => ";
      cin >> Code;
      
      while ((Code < 1) || (Code > 3))
      {
            cout << "Code must be in the range of 1 to 3." << endl
                  << "Enter the code for the part you want to buy => ";
            cin >> Code;
      }
      
      int* pStock = NULL;
      int* pQty   = NULL;
      
      if (Code == 1)
      {
            pStock = &AxleStock;
            pQty   = &AxleQty;
      }
      else if (Code == 2)
      {
            pStock = &BearingsStock;
            pQty   = &BearingsQty;
      }
      else /* if (Code == 3) */
      {
            pStock = &BrakeStock;
            pQty   = &BrakeQty;
      }
      
      cout << "There are " << *pStock << " pieces to buy. " << endl;
      cout << "How many of this part would you like => ";
      cin >> Integer;
      
      while (Integer <= 0 || Integer > *pStock)  
      {
            cout << "ERROR:  You must enter a number in the range of 1 to " << *pStock << " ==> ";
            cin >> Integer;          // try again
      }
      
      *pQty = Integer;
!!!!FROM HERE TO THE END OF THIS FUNCTION IT PRINTS OUT BUT DOESN'T ADD
TO THE CUSTOMER INVOICE. SO SOMEHOW I NEED TO LOOP THIS QUESTION AND UPDATE AS I GO ALONG WITHOUT ADDING MORE VARIABLES TO DISPLAY STOCK,
UPDATEPARTSSTOCK,TOTALCOSTPARTS, & DISPLAYINVOICE. IS THERE A WAY //!!
                  char Reply = ' ';
      cout << "Would you like to buy more parts? (Y/N) => ";
      cin >> Reply;
      Reply = toupper(Reply);
      
      while ((Reply != 'N') && (Reply != 'Y'))
      {
            cout << "ERROR: Valid responses are 'Y' or 'N'" << endl
                  << "Would you like to buy more parts? (Y/N) =>";
            cin >> Reply;
            Reply = toupper(Reply);
      }
      int Response;
            if (Reply == 'Y')
      {
            cout << "Enter the code for the part you want to buy => ";
            cin >> Response;
      }

}//END GetOrderQuantities
//********************************************************************************
//function : DisplayInvoice
//DISPLAYS THE INVOICE DETAILS
//********************************************************************************

void DisplayInvoice(int CustomerId, int AxleQty, int BearingsQty,
                              int BrakeQty,int AxleStock, int BearingsStock, int BrakeStock)
{
      string Part = " ";
      int Quantity =0;
      float Cost = 0;
####THE CUSTOMER ID DOES NOT CARRY FORWARD FROM THE USER INPUT HERE AND THE PARTS PURCHASED DON'T CARRY FORWARD ON TO THE INVOICE#####
      cout << "\nInvoice for Customer Number:  " << CustomerId << endl;

      cout << "Part\tQuantity\tCost" << endl;

      cout << setw(2) << Part
            << setw(10) << Quantity
            << setw(14) << "$ " <<Cost<<endl<<endl;
}
//***************************************************************************************
//function : TotalCostParts
//CALCULATES AND RETURNS THE TOTAL COST OF THE ITEMS THAT HAVE BEEN ORDERED
//***************************************************************************************
####THIS SEEMS TO WORK FINE BUT I CAN'T BE SURE BECAUSE FURTHER INPUT OF PARTS DOESN'T WORK IN PREVIOUS FUNCTION#####
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty)
{
      cout.setf(ios::fixed);
      cout.setf(ios::showpoint);
      cout.precision(2);
      float AxlePrice = 128.00,
            BearingsPrice = 25.50,
            BrakePrice = 30.00;
      double totalCost = AxleQty*AxlePrice+BearingsQty*BearingsPrice+BrakeQty*BrakePrice;
      
      cout <<setw(6)<<"Total Cost of parts:" <<"    $ "<<totalCost<<endl<<endl;
      return totalCost;
}
//************************************************************************************
//function : UpdatePartsStock
//UPDATES THE QUANTITY OF EACH ELEMENT THAT REMAINS IN STOCK
//************************************************************************************
###DONT' KNOW IF THIS FUNCTION IS WORKING BECAUSE CURRENT STOCK ON HAND DOESN'T APPEAR IF MORE PARTS ARE ORDERED####
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int& BrakeStock,
             int AxleQty, int BearingsQty, int BrakeQty)
{
      AxleStock    -= AxleQty;  
     BearingsStock -= BearingsQty;
     BrakeStock    -= BrakeQty;
     
}//END UpdatePartsStock
//**********************************************************************************
//function : Reorder
//UPDATES THE QUANTITY OF EACH ELEMENT THAT REMAINS IN STOCK
//***********************************************************

***THIS SEEMS TO WORK OK IF THE USER ONLY ORDERS ONE PART.  BUT IT NEEDS TO TAKE INTO CONSIDERATION MORE PARTS ORDERED.######
void Reorder(int AxleStock, int BearingsStock, int BrakeStock)
{
      
      if (AxleStock<=2)
      {
            cout << "The following parts should be reordered: "<<endl<<endl;
            cout << "Rear Axle"<< endl;
      }
      else if(BearingsStock<=10)
      {
            cout << "The following parts should be reordered: "<<endl<<endl;
            cout << "Bearings"<<endl;
      }
      else if (BrakeStock<=6)
      {
            cout << "The following parts should be reordered: "<<endl<<endl;
            cout << "Brake Pads"<<endl;
      }
      else  
      {
            cout << "No parts to be reordered at present. " << endl;
      }
      
}//END Reorder

THIS IS THE OUTPUT TO SCREEN

We supply parts for your vehicle.

Are there any Customers? (Y/N) =>y
Please enter Customer ID =>1234
Our current stock is:
Code    Part        Quantity On Hand   Price
 1      Axle               5           $ 128.00
 2      Bearings           20          $  25.50
 3      Brake Pads         12          $  30.00
Enter the code for the part you want to buy => 1
There are 5 pieces to buy.
How many of this part would you like => 5 @@OK TO HERE@@
Would you like to buy more parts? (Y/N) => y
Enter the code for the part you want to buy => 1

Invoice for Customer Number:  0
Part    Quantity        Cost
           0            $ 0.00

Total Cost of parts:    $ 640.00

The following parts should be reordered:

Rear Axle
Press any key to continue

KAZ
0
 

Author Comment

by:KazIT
ID: 10948385
I also have these 2 functions that I haven't used that Iam supposed to
void ReadInteger(int &Integer)
void Clear(void)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10950765
I started with GetOrderQuantities.


void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                              int AxleStock, int BearingsStock, int BrakeStock)
{
     // Reset Quantities
     AxleQty     = 0;  
     BearingsQty = 0;  
     BrakeQty    = 0;

     int Code    = 0;               //CODE
     int Integer = 0;
   
     // It's an infinite loop that breaks if the customer enters 0 to quit
     do
     {
         cout << "Enter the code for the part you want to buy (0 to quit) => ";
         cin >> Code;
     
         if (Code == 0)
         {
              cout << "Thank you for visiting us. Good Bye." << endl;
              return;
         }
             

         if ((Code < 1) || (Code > 3))
         {
              cout << "Code must be in the range of 1 to 3." << endl
                   << "Enter the code for the part you want to buy (0 to quit) => ";
              continue;   // JUMPS TO END OF LOOP
         }
     

         int* pStock = NULL;
         int* pQty   = NULL;
 
         if (Code == 1)
         {
              pStock = &AxleStock;
              pQty   = &AxleQty;
         }
         else if (Code == 2)
         {
              pStock = &BearingsStock;
              pQty   = &BearingsQty;
         }
         else /* if (Code == 3) */
         {
              pStock = &BrakeStock;
              pQty   = &BrakeQty;
         }
     
         Integer = -1;
         while ( Integer < 1 || Integer > *pStock)
         {
             cout << "There are " << *pStock << " pieces to buy. " << endl;
             cout << "How many of this part would you like (0 for none) => ";
             cin >> Integer;
     
             if (Integer < 1 || Integer > *pStock)  
             {
                 cout << "ERROR:  You must enter a number in the range of 1 to " << *pStock << " ==> ";
                 continue;
             }
     
             *pQty = Integer;
         }

         char Reply = ' ';
         while ((Reply != 'N') && (Reply != 'Y'))
         {
             cout << "Would you like to buy more parts? (Y/N) => ";
             cin >> Reply;
             Reply = toupper(Reply);
             if ((Reply != 'N') && (Reply != 'Y'))
             {    
                   cout << "ERROR: Valid responses are 'Y' or 'N'" << endl;
             }
         }
         if (Reply == 'N')
         {
              cout << "Thank you for visiting us. Good Bye";
              break;
         }
         while (Code != 0);           // The loop ends if Code == 0 or at any break;
     }

}//END GetOrderQuantities


>> void ReadInteger(int &Integer)


The first you wouldn't need as GetIntegerResponse() isn't much different (I would it call AskForCustomer). However, if you have to implement it, take this:

void ReadInteger(int &Integer)
{
      cin >> Integer;
}

and call it instead of  "cin >> Integer" in GetIntegerResponse();

>> void Clear(void)

I don't know whether it is a 'Clear Screen' or 'Clear Data'.

Try this:

#include <process.h>    // add it at top


void Clear(void)
{
     system("cls");   // clear the screen
}

You may call Clear() before Welcome() and before a next Customer could be entered.


>> THE CUSTOMER ID DOES NOT CARRY FORWARD FROM THE USER INPUT HERE

In main() you have to assign the CustomerId like this:

     // CALL FUNCTIONS
     Welcome();
     CustomerId = GetIntegerResponse(Lower,Upper);
     ....

Then it get passed to all subsequent function calls.

Regards, Alex









0
 

Author Comment

by:KazIT
ID: 10985389
Hi Alex,
Thankyou for your advice. I've implemented what you said and it is listed below but I get 2 errors when compiling
C:\Documents and Settings\Karen Stedman\My Documents\UNI\COIT11133\Assignment2Question1\a2q1 27thapril.cpp(227) : error C2137: empty character constant
C:\Documents and Settings\Karen Stedman\My Documents\UNI\COIT11133\Assignment2Question1\a2q1 27thapril.cpp(246) : error C2059: syntax error : '}'
Error executing cl.exe.

a2q1 27thapril.obj - 2 error(s), 0 warning(s)

I know it is missing a } or maybe it has one too many { but I can't seem to work out where.

void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
               int AxleStock, int BearingsStock, int BrakeStock)
{
      AxleQty =0;
      BearingsQty =0;
      BrakeQty =0;
      int Code =0;                
      int Integer =0;
      do
      {
      cout << "Enter the code for the part you want to buy (0 to quit)=>";
      cin >> Code;
            
      if(Code==0)
      {
      cout << "Thankyou for visiting us.  Good Bye."<< endl;
      return;
      }
            
      if((Code < 1)||(Code > 3))
      {
      cout << "Code must be in the range of 1 to 3." << endl
      << "Enter the code for the part you want to buy (0 to quit)=> ";
      continue;
      }
            
      int* pStock = NULL;
      int* pQty   = NULL;
            
      if (Code == 1)
      {
      pStock = &AxleStock;
      pQty   = &AxleQty;
      }
      else if (Code == 2)
      {
      pStock = &BearingsStock;
      pQty   = &BearingsQty;
      }
      else /* if (Code == 3) */
      {
      pStock = &BrakeStock;
      pQty   = &BrakeQty;
      }
            
      Integer =-1;
      while(Integer<1 || Integer >*pStock)
      {            
      cout << "There are " << *pStock << " pieces to buy. " << endl;
      cout << "How many of this part would you like (0 for none)? => ";
      cin >> Integer;
            
      if(Integer<1 || Integer > *pStock)
      {
      cout << "ERROR:  You must enter a number in the range of 1 to " << *pStock << " ==> ";
      continue;
      }
            
      *pQty = Integer;
      }
      
      char Reply='';
      while ((Reply != 'N') && (Reply != 'Y'))
      {
      cout << "Would you like to buy more parts? (Y/N) =>";
      cin >> Reply;
      Reply = toupper(Reply);
      if((Reply=='N') && (Reply != 'Y'))
      {
      cout << "ERROR:  Valid responses are 'Y' or 'N'" << endl;
      }
        }
      if(Reply=='N')
      {
      cout <<"Thank you for visiting us.  Good Bye.";
      break;
       }
      while(Code!=0);  //The loop ends if Code ==0 or at any break;
}
}//END GetOrderQuantities
0
 

Author Comment

by:KazIT
ID: 10985573
I've managed to get rid of the first error "Empty character contant by changing it to
char Reply = ' ';
0
 

Author Comment

by:KazIT
ID: 10986482
I've just found out that I shouldn't need to use pointers as in GetOrderQuantites that's not even covered in this part of the program.  So now more problems arise.  

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10987082

>>     while(Code!=0);  //The loop ends if Code ==0 or at any break;
>> }

// here the while statement is within the scope of do { ...  while } but it should be   do { ... } while (..);

So, change it to

     }
     while(Code!=0);  //The loop ends if Code ==0 or at any break;


>> I've just found out that I shouldn't need to use pointers as in GetOrderQuantites

???? Could you explain what you mean with that.


>> So now more problems arise

What problems??

Regards, Alex
0
 

Author Comment

by:KazIT
ID: 10991925
Thanks Alex for the tip on Brackets.  

In relation to the pointers.  In GetOrderQuantities
pointers aren't even in the course.
 
All I'm supposed  do in GetOrderQuantities is tell the program what stock I do have so that the user can then place a valid order. eg if stock is 5 you can't order 6.
 
Stock isn't getting changed (until later) but the quantity ordered is. This is all done by passing variables by reference or value.

Cheers
Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10993434
GetOrderQuantities not using pointers:


void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                        int AxleStock, int BearingsStock, int BrakeStock)
{
    AxleQty =0;
    BearingsQty =0;
    BrakeQty =0;
    int Code =0;                
    int Integer =0;
    do
    {
        cout << "Enter the code for the part you want to buy (0 to quit)=>";
        cin >> Code;
       
        if(Code==0)
        {
            cout << "Thankyou for visiting us.  Good Bye."<< endl;
            return;
        }
       
        if((Code < 1)||(Code > 3))
        {
            cout << "Code must be in the range of 1 to 3." << endl
                << "Enter the code for the part you want to buy (0 to quit)=> ";
            continue;
        }
       
        int nStock = 0;
        if (Code == 1)
            nStock = AxleStock;
        else if (Code == 2)
            nStock = BearingsStock;
        else /* if (Code == 3) */
            nStock = BrakeStock;
       
        Integer =-1;
        while(Integer<1 || Integer >*pStock)
        {          
            cout << "There are " << nStock << " pieces to buy. " << endl;
            cout << "How many of this part would you like (0 for none)? => ";
            cin >> Integer;
           
            if(Integer<1 || Integer > nStock)
            {
                cout << "ERROR:  You must enter a number in the range of 1 to " << nStock << " ==> ";
                continue;
            }
           
            if (Code == 1)
                AxleQty = Integer;
            else if (Code == 2)
                BearingsQty = Integer;
            else /* if (Code == 3) */
                BrakeQty = Integer;
       
        }
       
        char Reply=' ';
        while ((Reply != 'N') && (Reply != 'Y'))
        {
            cout << "Would you like to buy more parts? (Y/N) =>";
            cin >> Reply;
            Reply = toupper(Reply);
            if((Reply=='N') && (Reply != 'Y'))
            {
                cout << "ERROR:  Valid responses are 'Y' or 'N'" << endl;
            }
        }
        if(Reply=='N')
        {
            cout <<"Thank you for visiting us.  Good Bye.";
            break;
        }
       
    }
    while(Code!=0);  //The loop ends if Code ==0 or at any break;


}//END GetOrderQuantities

Regards, Alex
0
 

Author Comment

by:KazIT
ID: 10994658
Alex,
Am I right in assuming that
  while(Integer<1 || Integer >*pStock)

shoud be while(Integer<1 || Integer >nStock)?

Kaz
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10994674
Yes, you are right.

*pStock is dereferencing a pointer thus getting the value, while nStock is the value that must not be dereferenced.

Regards, Alex
0
 

Author Comment

by:KazIT
ID: 10994760
Thanks for that Alex.
Now I've compiled and run my code.
It now asks for the customer ID twice then shows the stock on hand ok but doesn't link the qty ordered is just keeps saying
How many of this part would you like? 1
ERROR: You must enter a number in the range of 1 to 0 ==>

Kaz
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 10995127
It looks like you had neglected my comment regarding GetIntegerResponse(..)

----------------------------- begin of old comment ----------------------------------------------

The problem is that you have two inputs, one with cin >> Response in GetIntegerResponse() and one in ReadInteger().

int GetIntegerResponse(int Lower, int Upper)
{
     
     int Response;
     
     cout << "Please enter your Customer ID =>"; !!DOESN'T SEEM TO MOVE ON FROM HERE!!!!
     cin >> Response;       // HERE YOU ALREADY GOT THE CUSTOMER-ID
     
     do
     {
          // HERE YOU TRY TO READ IT AGAIN
          // REMOVE THAT STATEMENT AND FUNCTION
          ReadInteger(Response);

          if (Response < Lower || Response > Upper)
          {
               cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                    << Upper << "=> ";
          }//END if
     }//END do/while
     while (Response < Lower || Response > Upper);
return Response;
}
void ReadInteger(int &Integer)
{
     cin >> Integer;
     while (cin.fail())
     {
          cin.clear();
          Clear();
          cout << "ERROR: You must enter a number => ";
          cin >> Integer;
     }
     Clear ();
}

So, you need this:

int GetIntegerResponse(int Lower, int Upper)
{
     int Response;    
     do
     {
          cout << "Please enter your Customer ID =>";
          cin >> Response;      

          if (Response < Lower || Response > Upper)
          {
               cerr << "\n\t\tERROR: Number must be between  " << Lower << " and "
                    << Upper << "=> ";
          }//END if
     }//END do/while
     while (Response < Lower || Response > Upper);

    return Response;
}

--------------------  end of old comment -------------------------------------------


In main() you need a statement like that:

    customerId = GetIntegerResponse(1000, 9000);


>> ERROR: You must enter a number in the range of 1 to 0 ==>

That also works at my prog. Did you pass Stock variables by reference to DisplayStock(int& AxleStock, int&... ).
If not you didn't get the values you assign in DisplayStock but the initial values from main().

You may init your Stock values in main()

     int AxleStock =5;          //AXLES IN STOCK
     int BearingsStock =20;     //BEARINGS IN STOCK
     int BrakeStock =12;         //BRAKES IN STOCK

Then you can remove these assignments in function DisplayStock.

Regards, Alex


0
 

Author Comment

by:KazIT
ID: 10995731
Thank you so much Alex for your help the points are well earned.

Kaz
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now