hi i am working on a shopping program where the user data consisting of his name , id and password has been given and the shopping items are divided into categories which is also given .It consists of music which has name , price and some tag number that item list has 3 items , electronic goods has 4 items and book has 5 items ..
So when the user enters his id and password , these inputs are checked with given data and if it is not valid it should ask user to enter his id and password again ,if it is valid the next screen would show the "Welcome " (it should login to his account ) and the list of categories ,shall i declare user id and password variable as global variable. My Question is in that category lists there would Add to cart list , since user can add many items to that list , so when the user selects the item that item has to be assigned to separate variable should this separate variable be an string variable or an array btw the item consists of its name,price and tag number , so when the user selects item from different categories all these selected item should get added into add to my cart list . i am confused in that bit .. and finally it should all the items in Add to cart list , like the one it shows in any shopping website and it should show the total price ..
And finally there will be logout option where the user logout , for this shall i assign login function to this ?
Best to keep the "login" function separate from the "log out" function. Also best to avoid global variables. They have a tendency to cause a lot of problems when you work with bigger codes. For the user Id and the password that depends on the use and security involved in the code. I would personally say use a string. They are easier to manipulate and compare. Hope this helps.
for add to cart list a user can add many items how to put all the items into single variable cause the list has to be shown when add to cart option is chosen in the end i mean can we do like that (i can pass these values as function arguments .). yeah instead of global variables i can pass the values as function arguments