Hi,
I have a program that is supposed to process dummy inventory data and print results to the screen. No matter what I try, I cant seem to get the program to process beyond a certain line. The code at that line is:
Inventory inv2(777,10,21.50); There are three different sections to display data and only the first one does. It seems that every time it gets to that line of code, it skips everything after that.
Here is the main program:
//*************************************************************************************
// The default constructor initializes itemNumber, quantity, cost and totalCost to 0. *
//*************************************************************************************
//*************************************************************************************
// The second constructor accepts item number, quantity and unit cost as arguments *
// storing them in the member variables and then calls setTotalCost. *
//*************************************************************************************
Inventory::Inventory(int inum, int qty, double cst )
{
if (inum >= 0)
itemNumber = inum;
else
cout << "Invalid item number! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
if (qty >=0)
quantity = qty;
else
cout << "Invalid quantity! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
if (cst >= 0)
cost = cst;
else
cout << "Invalid cost! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
setTotalCost();
}
//*************************************************************************************
// setItemNumber accepts an integer and copies it to itemNumber variable. *
//*************************************************************************************
void Inventory::setItemNumber(int inumber)
{
if (inumber >= 0)
itemNumber = inumber;
else
cout << "Invalid item number! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
}
//*************************************************************************************
//setQuantity accepts an integer and copies it to quantity variable. *
//*************************************************************************************
void Inventory::setQuantity(int qty)
{
if (qty >=0)
quantity = qty;
else
cout << "Invalid quantity! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
}
//**************************************************************************************
//setCost accepts a double and copies it to cost variable. *
//**************************************************************************************
void Inventory::setCost(double cst)
{
if (cst >=0)
cost = cst;
else
cout << "Invalid cost! Number must NOT be less than zero.";
}
//**************************************************************************************
// setTotalCost calculates total cost (quantity * cost) and stores in totalCost *
// variable. *
//**************************************************************************************
//**************************************************************************************
// getItemNumber returns value of itemNumber. *
//**************************************************************************************
int Inventory::getItemNumber() const
{
return itemNumber;
}
//**************************************************************************************
// getQuantity returns value of quantity. *
//**************************************************************************************
int Inventory::getQuantity() const
{
return quantity;
}
//**************************************************************************************
// getCost returns the value of cost. *
//**************************************************************************************
//**************************************************************************************
// getTotalCost returns the value of totalCost. *
//**************************************************************************************
Inventory::Inventory(int inum, int qty, double cst )
{
if (inum >= 0)
itemNumber = inum;
else
cout << "Invalid item number! Number must NOT be less than zero.";
exit(EXIT_FAILURE); //will always run, program ends here
if (qty >=0)
quantity = qty;
else
cout << "Invalid quantity! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
if (cst >= 0)
cost = cst;
else
cout << "Invalid cost! Number must NOT be less than zero.";
exit(EXIT_FAILURE);
setTotalCost();
}