### need help solving this problem, i am falling behind!!!

For number 2 it doesn't even search, i don't know what is the problem? and after searching how do i make it change the name and quantity of product.

I also need help with number 3

We need a point of sale system for the new grocery store I am planning to open. Here are the main features of this program:

1) Enter a Product

This feature allows user to enter a new product into the system. Program asks store owner to enter a product name (ex. Snicker, SpringWater etc), quantity (how many of this product in inventory), and sale price. Assume that product name does not have any space in it. If the product already exist, tell store owner that the product is already in inventory.

2) Change Inventory

This feature allows store owner to change the quantity of a product in the inventory. Program asks user for the name of the product and new quantity. It will search the products in the system, find the product user specified and change its quantity to the new number specified by store owner.

3) Make Sale

This feature allows store owner to record the sale of a product. Program asks user for the name of the product and how many of this product is sold. It will search the products in the system, find the product user specified and deducts the specified quantity from the inventory.

4) Inventory Report

This feature allows store owner to display inventory report. The report should display each product on a separate line. For each product, display the name, sale price and quantity. At the end of the report also display the worth of the whole inventory. worth of each product is quantity of that product times the sale price. the worth of the whole inventory is the sum of the worth of all products.

5) Exit

Exits the program.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283`` ``````#include #include using namespace std; class GroceryRecord { public: string Name; string Quantity; }; void EnterProduct(GroceryRecord Grocerystuff[], int GroceryCount) { GroceryRecord gr; cout << "Enter name of product: "; cin >> gr.Name; cout << "Enter the Quantity of product: "; cin >> gr.Quantity; cout << endl; cout << "You Entered" << endl; cout << "Name: " << gr.Name << endl; cout << "Quantity: " << gr.Quantity << endl << endl << endl; Grocerystuff[GroceryCount] = gr; } int main() { GroceryRecord Grocerystuff[100]; int GroceryCount = 0; while(true) { cout << "1- Enter a Product" << endl; cout << "2- Change Inventory" << endl; cout << "3- Make Sale" << endl; cout << "4- Inventory Report" << endl; cout << "5- Exit" << endl; cout << "What is your choice? "; int choice; cin >> choice; if(choice == 5) break; if (choice == 1) { EnterProduct(Grocerystuff, GroceryCount); GroceryCount++; } else if(choice == 2) { string name; cout << "Enter name: "; cin >> name; for(int i=0; i < GroceryCount; i++) if (name == Grocerystuff[i].Name) cout << "the Quantity is: " << Grocerystuff[i].Quantity << endl; } else if(choice == 3) { } else if(choice == 4) { for(int i=0; i < GroceryCount; i++) { cout << "Name: " << Grocerystuff[i].Name << " Quantity: " << Grocerystuff[i].Quantity << endl; } } } system("PAUSE"); return 0; }``````
Last edited on
Number 2 searches and returns the quantity fine, you just have to input one first.

I selected option 1 and named it "ham" and said the quantity was 2, then I selected 2 and input "ham" and it spit out "quantity is:2".

You just have to implement the rest of the code.

Have the loop assign a value to a global variable temporarily containing the name and location of the item then code the input/output to the user to modify it.

What is your problem with number 3?
Beginner007 wrote:
how do i make it change the name and quantity of product.

according to your problem description you don't have to change the name only the quantity.

agnophilo wrote:
Have the loop assign a value to a global variable temporarily containing the name and location of the item then code the input/output to the user to modify it.

using global variables should be avoided and isn't really needed here. You just need to ask the user to input a new quantity then save that quantity to `Grocerystuff[i].Quantity` You should also check and make sure quantity isn't less than zero

Also on line 10 you declare quantity as a string. Quantity should be an int;

side note: because you make your class data members public, and you don't use any member methods. I would use a struct instead, but thats just my opinion.
Last edited on
i am confused why should quantity in line 10 be an int; it will give out the same out come as i put. i would really appreciate it if you show how to fix it using the code. i am falling behind in this class.
Last edited on
Here is an example

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` ``````else if(choice == 2) { string name; int adjust; cout << "Enter name: "; cin >> name; cin.ignore(); for(int i=0; i < GroceryCount; i++) { if (name == Grocerystuff[i].Name) { cout << "the Quantity is: " << Grocerystuff[i].Quantity << endl; cout << "Enter quantity adjustment: "; cin >> adjust; cin.ignore(); temp = Grocerystuff[i].Quantity; temp += adjust; while (temp < 0) { cerr << "Quantity can't be less than 0 " << endl; cout << "the Quantity is " << Grocerystuff[i].Quantity << endl; cout << "Enter quantity adjustment: "; cin >> adjust; cin.ignore(); temp = Grocerystuff[i].Quantity; temp += adjust; }/*end of while loop*/ Grocerystuff[i].Quantity = temp; cout << "New quantity: " << Grocerystuff[i].Quantity << endl; break; }/*end of if*/ }/*end of for loop*/ }/*end of choice == 2*/``````

Please note that this code won't work unless you change Line 10 `string Quantity;` to `int Quantity;`

Also it would probably be better to use a switch statement instead of the if else statements, but again thats just my opinion

Beginner007 wrote:
i am confused why should quantity in line 10 be an int

because the int data type allows for operations such as +,-,*,/. Your program requires you to change the value of quantity. To do this you will need to use the + operator. If you use a string you would have to first convert the string to an int. Then do whatever operation is needed. Then convert the int back to a string to store it in the array. This is just a lot of extra work that isn't needed.

Last edited on
thanks a lot, now i will try to solve number 3
Topic archived. No new replies allowed.