write a program handling an inventory, by storing number of item codes inside an array (numeric values), a price for each item, and a quantity in the inventory.
the values should be created by default at each program start with a minimum of 5 items, prices and quantities, and then the program should print out all items that cost more than 100 pounds, and the items that quantities less than 10 pieces in the inventory.
the print out should be printed in a tabular form ( item number, quantity, price).
and should give the user the option to enter another element, to edit a given item, to delete an item, to re-enter the values if the program had an improper input ( like a negative value in the quantity, or price.
for (i=0; i<r; ++i)
{
for (j=0; j<c; ++j)
printf("%10d", a[i][j]);
printf("\n");
}
printf("the items that have a price more than 100 are:\n");
for(i=0;i<r; ++i)
{
if (a[i][1]>100)
{
temp = a[i][0];
printf("item code %d\n", temp);
}
}
printf("\nthe items that have a quantity less than 10 are:\n");
for(i=0;i<r; ++i)
{
if (a[i][2]<10)
{
temp = a[i][0];
printf("item code %d\n", temp);
}
}
printf("do u want to edit an item(0 for no,1 for yes)?\n");
scanf("%d", &op);
if (op==1)
{
while(found==0)
{
printf("enter item code\n");
scanf("%d", &temp);
for(i=0;i<r; ++i)
{
if(a[i][0]==temp)
{
found=1;
printf("Please enter code, price, quantity\n");
for (j=0; j<c; ++j)
{
scanf("%d", &a[i][j]);
for (i=0; i<r; ++i)
{
for (j=0; j<c; ++j)
printf("%10d", a[i][j]);
printf("\n");
}
return (0) ;
}
----------------------------------------------------
i wanna know how to give the user the option to enter another element, and how to delete only one item!!
thank u
Firstly, I suggest that, for simplicity, you should use 3 one dimensional arrays, instead of one 2 dimensional.
For entering elements you could use realloc ( http://www.cplusplus.com/reference/clibrary/cstdlib/realloc/ ) to reallocate the arrays and then write the last element to them. Another option is to allocate a lot more memory then you initially need..
For deleting, you just have to move every element, below the deleted one, up. If you want to delete arr[n], do
arr[n] = arr[n+1]
arr[n+1] = arr[n+2]
and so on, until
arr[k-1] = arr[k],
where k is the number of elements in array. I'm sure you'll be able to put that into a loop.