Basically, I am supposed to create a program to add, view, remove and update products. However I have only been able to successfully implement add and view. If anyone can help me with the other functions, it would be greatly appreciated. Here is the code so far:
#include<iostream>
#include<cstdlib>
#include <string>
using namespace std;
int x;
int c = 0;
int operation()
{
cout << "////////////////////////////MENU\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" << endl;
cout << "1 - Add Product" << endl;
cout << "2 - View Products" << endl;
cout << "3- Delete Product" << endl;
cout << "4- Update Product" << endl;
cout << "5- Exit" << endl;
cout << "Enter the number of the option you wish to use" << endl;
cin >> x;
return x;
}
struct products {
char name[1];
int quantity;
float price;
int productID;
string description;
};
int main()
{
products a[100];
Initialize:
operation();
switch (x)
{
case 1:
cout << "You choose to add a product" << endl << endl;
for (int i = (1 + c); i <= 100; i++)
{
if (i>100)
{
cout << "You exceed the number of your products" << endl;
}
else
{
cout << "Please enter the name of the product number " << i << endl;
cin >> a[i].name;
cout << "Now please enter the quantity of " << a[i].name << endl;
cin >> a[i].quantity;
cout << "Now please enter the price of " << a[i].name << endl;
cin >> a[i].price;
cout << "Now please enter the product ID" << a[i].name << endl;
cin >> a[i].productID;
cout << "Now please enter the product description" << a[i].name << endl;
cin >> a[i].description;
cout << "Product is successfully added" << endl << endl;
c++;
goto Initialize;
}
}
break;
case 2:
cout << "You choose to view the products" << endl << endl;
if (c == 0)
{
cout << "You have no products yet" << endl << endl;
goto Initialize;
}
else {
for (int i = 1; i <= c; i++)
{
cout << "Product no." << i << " name is " << a[i].name << endl;
cout << "Product no." << i << " quantity is " << a[i].quantity << endl;
cout << "Product no." << i << " price is " << a[i].price;
cout << endl << endl;
}
goto Initialize;
}
break;
What I basically need is the codes to fill in the switch statement cases 3 and 4 to delete and update product respectively. I need it solved badly, would seriously appreciate the help, and thank you in advance
Please use code tags - select your code text and pres <> in toolbox on the right.
What I basically need is the codes to fill in the switch statement cases 3 and 4
Perhaps if you would like to show us your attempt at solving it first so we can address specific problems you encounter. It is not a good move just to ask for the code without trying.
This is extremely counterproductive, because it a.) prevents further discussion of the topic b.) prevents other people from benefiting from the information you were given c.) fills the forum with a form of noise essentially equivalent to spam.