OK, let's see... You wanted a code example, ok. Well, the structures I was hinting at are called
stucts and they are very useful for cases such as this one. Say you want to have a structure representing the clothes you own, then the code may look something like this:
- #include<iostream>
-
#include<string>
-
-
using namespace std;
-
-
typedef struct clothing_item {
-
int position;
-
string name;
-
string type;
-
string colour;
-
double size;
-
int amount;
-
} Item;
-
-
int main() {
-
Item * items = new Item[4];
-
-
items[0].name = "red jacket";
-
items[0].type = "jacket";
-
items[0].colour = "red";
-
items[0].size = 41;
-
items[0].amount = 1;
-
-
items[1].name = "white shirts";
-
items[1].type = "shirt";
-
items[1].colour = "white";
-
items[1].size = 40.5;
-
items[1].amount = 2;
-
-
items[2].name = "pairs of blue jeans";
-
items[2].type = "trousers";
-
items[2].colour = "blue";
-
items[2].size = 30;
-
items[2].amount = 3;
-
-
items[3].name = "pair of black socks";
-
items[3].type = "socks";
-
items[3].colour = "black";
-
items[3].size = 42;
-
items[3].amount = 1;
-
-
cout << "Here are the items I own:" << endl;
-
for(int i = 0; i<4; i++) {
-
cout << (i + 1) << ". " << items[i].amount << " " << items[i].name << endl;
-
}
-
-
cout << "Which one do you want to know more about? ";
-
int nr;
-
cin >> nr;
-
cout << "This item is " << items[nr - 1].colour << endl;
-
-
// Just to stop the window from closing
-
cin >> nr;
-
}
Next I'd read in the books you want to add to the cart in a loop. The easiest way to do that is probably to have the user enter the number of an item to add that item to the cart or a 0 if he wants to finish. Then you can add up the prices.