Hi..
I'm writing a code for the cash receipt program....
before this,i already make this kind of program..
but the program that i've made before is simply doing this task only :
//ask the user to enter the product information...
Enter the product id :
Enter the product name :
Enter the price for a single item :
Enter the quantity :
would you like to enter another item ? :
//then this program will display the product id,item,price,quantity,and sale....
as you can see from above,the program that i've made before will take the informations of the product one by one,and then display them back together with the price and also the product sale...
But,I wanna try something that is a little bit different...
I want to make a program that will ask the user to enter only the product id,then the program will automaticly identify its name and its price and finally display them together with the product sale....
here is attempt :
#include <iostream>
#include<iomanip>
using namespace std;
int main () {
struct record {
int id;
string item;
};
record product[100];
int i=0,t=0;
char answer;
do {
cout<<"Enter The Product Id :";
cin>>product[i].id;
cout<<"Enter more item ?";
cin>>answer;
}while (answer=='y' || answer=='Y');
switch (product[i].id){
case 1001 :
product[t].item="shirt";
break;
case 1002 :
product[t].item="book";
break;
}
for (int index=0; index<=i; index++)
{
cout<<product[index].item;
}
}
This program is not finish yet because i'm still struggling to display all the names of the products....
This program so far only be able to display the last name of the product only...
I know my mistake here is that is product[t].item="........".
each time the user enter the different product id,the value of
product[t].item will be changed...So thats why at the end,this program will only display the last value which has been assigned to the product[t].item...
I've tried so hard,but so far i still cant figure out what is the actual way to do this....
Please help me....
Thank You :)