Hi there friends I have an inventory program that stores all the data entered by a user.
I am having trouble trying to output the infos entered. I tried to use for loop but no luck. Mine only outputs the last set of keyed in information. It will not output information inputted earlier. Please help me.
For Example:
How many products?
>>2
input product 1
>>shampoo
How many shampoo?
cin>>2
cin>>brand[1]
cin>>price
cin>>stock
cin>>sold
cin>>brand[2]
cin>>price
cin>>stock
cin>>sold
Now all of these inputted by a user will be outputted and must look something like this:
Shampoo[1] : rejoice
Price: Php71.25
Stock: 100
Sold: 26
Shampoo[2] : Palmolive
Price:Php70.50
Stock: 150
Sold: 35
Shampoo[3] : h&s
Price:Php99.75
Stock: 100
Sold: 50
PRODUCT[2] SOAP
How Many Soap? 2
Soap[1]: safeguard
Price:Php25.50
Stock: 250
Sold: 56
Soap[2]: bioderm
Price:Php18.50
Stock: 100
Sold: 10
But mine will only output this part:(which is the last set of inputted information)
cin>>brand[2]
cin>>price
cin>>stock
cin>>sold
=======================================================================================
Now here is my code:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <windows.h>
using namespace std;
struct inventory
{
string brand[10];
string name[10];
int numofprod;
int price;
int stock;
int sold;
int prodleft;
int prodnum;
int prod;
}input;
int main()
{
int ctr;
int numofprod;
cout<<"Enter Number of Products (1 to 10 only)"<<endl;
cin>>input.numofprod;
while (input.numofprod>10)
{
cout<<"Invalid Input, Enter only numbers from 1 to 10"<<endl;
cin>>input.numofprod;
}
for (int i=0;i<input.numofprod;i++)
{
for (int i=0;i<input.numofprod;i++)
{
cout<<"Enter Type of Product"<<endl;
cin>>input.name[i];
cout<<"How many "<<input.name[i]<<"?";
cin>>input.prod;
for(i=0;i<input.prod;i++)
{
cout<<input.name[i]<<" brand:"<<"["<<i+1<<"]"<<endl;
cin>>input.brand[i];
cout<<"Enter a price"<<endl;
cin>>input.price;
cout<<"Enter stock"<<endl;
cin>>input.stock;
cout<<"Enter sold"<<endl;
cin>>input.sold;
cout<<endl;
}
}
}
cout<<"*********************INVENTORY SYSTEM C++.2***********************"<<endl;
for (int i=0;i<input.numofprod;i++)
{
for (int i=0;i<input.numofprod;i++)
{
cout<<"Type of Product"<<endl;
cout<<input.name[i];
cout<<endl;
cout<<"Num of Prod:"<<endl;
cout<<input.prod;
cout<<endl;
for(i=0;i<input.prod;i++)
{
cout<<input.name[i]<<" brand:"<<"["<<i+1<<"]"<<endl;
cout<<input.brand[i]<<endl;
cout<<"price"<<endl<<endl;
cout<<input.price<<endl;
cout<<"stock"<<endl<<endl;
cout<<input.stock<<endl;
cout<<"sold"<<endl<<endl;
cout<<input.sold<<endl;
cout<<endl<<endl;
}
}
}
system ("pause");
return 0;
}
Please help me guys...