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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <string>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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.