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

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.

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;

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.

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.

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. :)

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.

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?

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.

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.

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.

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);

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.

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

}//END main
//*******************************************************************************
//function : Welcome
//DISPLAYS A WELCOME MESSAGE THAT INCLUDES YOUR STUDENT NO AND NAME
//*******************************************************************************

}//END Display Stock
//****************************************************************************
//function : GetOrderQuantities
//OBTAINS FROM THE USER THE ITEM CODE AND THE QUANTITY OF EACH
//ITEM THAT ARE REQUIRED BY THE USER
//****************************************************************************

*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);

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

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 ==>

-------------------- 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().

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…

Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …

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…