I'm having some trouble some parts of a progarm. I have to write a progarm which allows a user to enter inventory data for item in a store. This data should be stored in a text file on disk, with each items data on a single line. The data for each item must be entered on separate lines
with separate prompts is this order:
Stock Number (at most 5 characters long)
Price
Quantity in stock
I can assume the user will enter numeric values for price and quantity.
The progarm should validate the price to require it to be between 0.00 and 10000.00. Repeatedly prompt for the price until it is within that range. However, if the user enters -999.00, escape from the validation loop and abandon that record. In other words, if the user enters an illegal value, ask for it again and agin until the user enters a valid number or enters -999.00, then abandon that record and start prompting for a new record by asking for its stock number.
I dont need to validate the other data for this progarm.
Store the data on a disk with one record on each line of the file with the fields in the order shown above.
This program should prompt the user for a name of the flie to be created. If the user just presses <enter>, then the progarm should use the default name of "stock.dat" If the user does not include an extention on the file name, the progarm should append ".dat" to the user's file name.
This is what I have so far:
Most my problems are in the validation. I cant seem to validate the data correctly. If anyone can help at all, I thank you for it.
Most of these headers do not exist in standard C++ (according to the 10 year old standard). Considering the exercise, it is also unclear why you include things like stdio.h or ctype.h. Try starting anew with
The return type of main is int, has always been int and there is no plan to change that.
Originally Posted by bmcginnis
char FileName[20];
Why not declare filename as std::string? Then appending ".dat" would simply be a += operation.
No more comments before you make your code readable.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Think about any possible value where that could evaluate true. A number could never be both greater than 10,000 and less than 0 at the same time. It could be greater than 10,000 or less than 0 though.
Bookmarks