Question: Hey! So I made this program and I need help on checking it because something's wrong and I can't figure out what. The program is

Hey! So I made this program and I need help on checking it because something's wrong and I can't figure out what. The program is supposed to request the user to type a number of items that he or she wishes to make. Afterwards, the user is supposed to input certain conditions about that item such as descriptions, costs, amounts and so on and so forth. I had finished the program but it doesn't seem to get past the description of the first item. Thank you for your time!

#include

#include

using namespace std;

class Inventory {

private:

int itemNumber;

string description;

int quantity;

double cost;

double totalCost;

int counter;

public:

Inventory () {

itemNumber = 0;

description = "";

quantity = 0;

cost = 0;

totalCost = 0;

counter = 1;

}

Inventory (int n_itemNumber, string n_description, double n_cost, int n_quantity) {

itemNumber = n_itemNumber;

description = n_description;

cost = n_cost;

quantity = n_quantity;

}

double setTotalCost () {

totalCost = cost * quantity;

}

string setDescription(string prompt_text, int counter) {

string n_description;

cout << prompt_text << " " << counter << ": ";

getline(cin, n_description);

description = n_description;

}

int setitemNumber (string prompt_text, int counter, string error_message_text) {

int n_itemNumber;

while (1) {

cout << prompt_text << " " << counter << ": ";

if (cin >> n_itemNumber) {

cin.clear();

cin.ignore(4096,' ');

break;

} else {

cout << "Try again ";

cin.clear();

cin.ignore(4096,' ');

}

}

itemNumber = n_itemNumber;

}

int setQuantity (string prompt_text, int counter, string error_message_text) {

int n_quantity;

while(1) {

if (cin >> n_quantity) {

cin.clear();

cin.ignore(4096, ' ');

break;

} else {

cout << "Try again ";

cin.clear();

cin.ignore(4096, ' ');

}

}

quantity = n_quantity;

}

double setCost (string prompt_text, int counter, string error_message_text) {

double n_cost;

while(1) {

if (cin >> n_cost) {

cin.clear();

cin.ignore(4096, ' ');

break;

} else {

cout << "Try again ";

cin.clear();

cin.ignore(4096, ' ');

}

}

cost = n_cost;

}

int getitemNumber () {

return itemNumber;

}

string getDescription() {

return description;

}

int getQuantity () {

return quantity;

}

double getCost () {

return cost;

}

double getTotalCost () {

return totalCost;

}

};

int main () {

int numberofitems;

while (true) {

cout << "How many items in inventory (1-5)? ";

if (cin >> numberofitems) {

if (numberofitems >= 1 && numberofitems <= 5) {

break;

} else {

cout << "Try again ";

continue;

}

} else {

cout << "Try again ";

cin.clear();

cin.ignore(4096,' ');

}

}

Inventory items[numberofitems];

for (int itemcount = 0; itemcount < numberofitems; itemcount++) {

Inventory item;

item.setitemNumber("Enter the item number for number ", itemcount+1, "Try again" );

item.setDescription("Enter the description for item number ", itemcount+1);

item.setQuantity("Enter a quantity for item number ", itemcount+1, "Try again");

item.setCost("Enter a cost for item number ", itemcount+1, "Try again");

items[itemcount] = item;

}

cout << endl << "Inventory Items" << endl << endl;

for (int i = 0; i < numberofitems; i++) {

cout << "Item Number: " << items[i].getitemNumber() << endl;

cout << "Item Description: " << items[i].getDescription() << endl;

cout << "Quantity: " << items[i].getQuantity() << endl;

cout << "Cost: " << items[i].getCost() << endl;

cout << "Total Cost: " << items[i].getTotalCost() << endl;

cout << endl;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!