Inventory Class

I wrote this program but I am not sure how to run the program if i would like to run it again. I need your help. Please advice.


#include <iostream>
using namespace std;

class Inventory
{ private:
int itemNumber;
int quantity; //quantity of the items on-hand
double cost; //wholesale per-unit cost of the items
double totalCost; //total inventory cost of the item (items * cost
public:
Inventory(){
itemNumber = 0;
quantity = 0;
cost = 0;
totalCost = 0;}
Inventory(int iNum, int iQnty, double iCost){
itemNumber = iNum;
quantity = iQnty;
cost = iCost;
setTotalCost(quantity, cost);}

void setItemNumber(int iNum) {itemNumber = iNum;}
void setQuantity(int iQnty) {quantity = iQnty;}
void setCost(double iCost) {cost = iCost;}
void setTotalCost(int, double) {totalCost = quantity * cost;}

int getItemNumber() {return itemNumber;}
int getQuantity() {return quantity;}
double getCost() {return cost;}
double getTotalCost() {return totalCost;}
};

int main()
{
int itemNumber;
int quantity;
double cost;
double totalCost;
char again;

cout << "Enter the Item Number: ";
cin >> itemNumber;
while (itemNumber < 0){
cout << "Please enter a positive value for the Item Number: ";
cin >> itemNumber;}
cout << "Enter the Quantity of the item: ";
cin >> quantity;
while (quantity < 0){
cout << "Please enter a positive value for the Quantity of the item: ";
cin >> quantity;}
cout << "Enter the Cost of the item: ";
cin >> cost;
while (cost < 0){
cout << "Please enter a positive value for the Cost of the item: ";
cin >> cost;}

Inventory information(itemNumber, quantity, cost);

totalCost = information.getTotalCost();
itemNumber = information.getItemNumber();
cost = information.getCost();
quantity = information.getQuantity();
cout << "The Item Number is: " << itemNumber << endl;
cout << "The Quantity is: " << quantity << endl;
cout << "The Cost is: " << cost << endl;
cout << "The Total Cost is: " << totalCost << endl;

// Ask user if they wish to perform another one
do{
cout << "Do you wish to perform another one? (Y / N)" << endl;
cin.ignore();
cin >> again;
system("CLS");
if ((again == 'N') || (again = 'n'))
exit(EXIT_SUCCESS);}
while (again == 'y' || again == 'Y');{
cin >> again;}


return 0;
}
Last edited on
Probably (because I haven't tried it):

Move your
do{
before the line
cout << "Enter the Item Number: ";

Remove the end brace } at the end of line
exit(EXIT_SUCCESS);}

Replace lines
1
2
while (again == 'y' || again == 'Y');{
cin >> again;}

with
} while ( true );

The program will then loop until the program concludes with exit(EXIT_SUCCESS);


Topic archived. No new replies allowed.