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.
//p3b
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
void getPrice(float &price);
void getQuantity(int &quantity);
void getStockNum(char stockNum[]);
void getFileName(char FileName[]);
void main()
{
char stockNum[6];
float price ;
int quantity ;
char FileName[20];
getStockNum(stockNum);
getPrice(price);
//===============================
// loop for price being -.999
//===============================
getQuantity(quantity);
getFileName(FileName);
strcat(FileName,".dat");
ofstream project3b(FileName, ios::out);
project3b << "Stock Number: "<<stockNum << "\n" << "Price: "<<price << "\n" << "Quantity: "<<quantity;
cout << "\n\n";
}
//========================
//get stockNum
//========================
void getStockNum(char stockNum[])
{
cout << "Stock Number: ";
cin >> stockNum;
if(strlen(stockNum, '\0'))
exit(1);
}
//==========================
//get the price
//==========================
void getPrice(float &price)
{
cout << "Price: ";
cin >> price;
if (price > 10000.00 && price <0.00 )
{
cout<<"Enter a valid Price: ";
getPrice(price);
}
if (price == -.999)
{
cout<<"exiting progarm...";
exit(1);
}
}
//===========================
//get the quantity
//===========================
void getQuantity(int &quantity)
{
cout << "Quantity: ";
cin >> quantity;
}
//===========================
//get file name
//===========================
void getFileName(char FileName[])
{
cout << "\nEnter the name of the file you want to create with extention: ";
cin >> FileName;
}

