i have added two users details in main function when i execute the program it only adds the total values of 1st customer but when i choose 2nd user it doesnt add total values . i dont know how to do ,as i have initialized no of music items as 3 by using categoryDetailsObject.musicCount as 3 can i do it same way for customers as well but since array is used (customerDetailsObject[2]) like customerDetailsObject[].customerCount or something i dont know how to do it can anyone help me ..
musicCount is in category class its not a full program i tried to add it but it exceed the no of lines required here is the full program the next half is in next reply column
Here how the program works ------ when i run the program it asks for login id and pass so when i give the correct id and pass it shows the list of catgories in that when i choose say music . in that it has 3 items so when i click one of them and add to cart that item will be added into the cart similarly when i choose multiple items and add them they will be added in add to cart , when i click view cart it will show the list of items which has been added and total value .
but my problem is since there are multiple customers when i choose 1st customer that is david the program runs properly ( it shows all the items which have been added and also shows total cost of all the items) but when i choose customer rahul after adding the items into add to cart , in the view cart it doesnt show the list of items and total cost , something needs to be changed in for loop used in viewCart function () .for (int i=0; i<itemDetailsCount; i++) so that current/logged in user choosen items get added in add to cart and the total cost of all the items get added up.
say tomo if i want to add 3 more items in music category i'll have to change categoryDetailsObject.musicCount = 5 and give the data in main function and automatically [b]musicCount variable[/b] is used in for loop in chooseMusicItemDetails function () will get changed to 5
similarly when i want to add 4 more customers i'll have to create customerCount variable but since customerDetailsObject is an array the above step will not work is there any way to do so that when i want to add customers i'll just add how many customers are there in that variable and use that variable in for loop used in validity function() ( (for int i=0 ; i<customerCount ;i++))
in the view cart it doesnt show the list of items and total cost
Yes, that is because in viewCart() you are using customerDetailsObject[0] while you want customerDetailsObject[matchedAccount]
You should search for all 'customerDetailsObject' and make sure that you're using 'matchedAccount' with it.
If you want a dynamic array for your customer you may use std::vector that holds the size()/number of elements. The same applies to the items. A push_back() automatically increases the size() but behaves otherwise like an array
i tried using matchedAccount in customerDetailsObject[matchedAccount] , it didnt worked out
What does it mean? Line 138 does the right thing but line 146 doesn't when you use customerDetailsObject[matchedAccount]...?
Wait... viewCart() is part of customerDetails so:
1 2 3 4 5 6
for (int i=0; i<itemDetailsCount; i++)
{
cout<<"\nName - "<<itemDetailsObject[i].name<<endl; // no customerDetailsObject[0]. necessary
cout<<"Cost - Rs."<<itemDetailsObject[i].cost<<endl; // neither here
cout<<"Sku No - "<<itemDetailsObject[i].sku<<endl; // neither here
}
This should work
in main function if i wanted to add few more customers how to do it well can i do same way where i have written categoryItemsDetails.musicCount = 3
Yes, but you have to increase the size of customerDetailsObject as well.
If you want an unlimited amount you should use std::vector.
All in all your structure is rather inconvenient/not really intuitive. Like try to incorporate functions like 'musicAddToCart()', 'electronicAddToCart()', ... into the class customerDetails. E.g. class customerDetails { ... AddMusicToCart(item) ... };
Avoid using global variables (especially with names like ch). My idea of a structure would be like that:
class CItem
{
....
};
class CCustomer
{
...
void TakeItem(CItem items[], int &count) // one of the items music etc from categoryDetailsObject
{
cout << "What item";
cin >> item_idx;
m_Cart[m_Count] = items[item_idx];
++m_Count;
--count;
}
// Details
...
CItem m_Cart[...];
int m_Count;
};
class CShop
{
...
void login();
...
CItem m_Items[...];
int m_ItemCount;
CCustomer m_Customers[...];
int m_CustomerCount;
int m_CurrentCustomer; // Or better: CCustomer *m_CurrentCustomer
};
yes in line 138 it works idk why its not working in 146 cause when user Rahul is selected it adds up and even in the incrementer it increments every time i add an item but its not showing in view cart function that is line 146 .
in line 146 u say that customerDetailsObject isnt required but u should know which customer has logged has added the items in add to cart () . ??
because when it is customerDetailsObject[0]. that is when user is david ,, when the user adds the items in add to cart () in the viewCart () it shows up all the items that user has selected ..
but its not happening when user Rahul is logged in it doesnt show up in viewCart ().
yes in line 138 it works idk why its not working in 146 cause when user Rahul is selected it adds up and even in the incrementer it increments every time i add an item but its not showing in view cart function that is line 146 .
You implemented the choosing mechanism with recursions. That's not good. You need to get out of the function when the user selects "Back" instead of going 'deeper' in your display...() functions. You need a loop in your display...() functions if the user chooses the ...AddToCart() function (return if "Back" or "MainPage"). In case of "MainPage" the display...() functions should return false so that the the caller function can return as well (false) to really get to the chooseCategory().
in line 146 u say that customerDetailsObject isnt required but u should know which customer has logged has added the items in add to cart () . ??
Sure. You're already 'inside' the customerDetailsObject. Nothing more has to be done. You should ban the global variables anyway
conclusion: Get rid of the recusion (the function that calls itself) and get more into OOP
It took me more than 1/2 hour to revamp your menu. Do you understand what I did and why i did it.
No I didn't touch your card problem. Like I mentioned before your ...AddToCart() functions can be easily incorporated into customerDetails like viewCart() alread is.