Create a container to keep all the selections in it. The container may have any number of items in it. If you have been advised that no order will have more than 7 items associated with it, so be it, but it could have 1 or 3 or 4 or 7 so don't assume it will have no more and no less than 7 items. Then when the customer has completed the order you can loop through the container representing the order and print out the items, keep track of the total price of the items, calculate the tax and add the tax to the price of the items to get the total cost of the order. This can all be done using arrays, but be sure the arrays are big enough to be able to hold any given reasonable order, say 1000 items or so (unless you've been told that the maximum number of items in any given order will some specified value).
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Here's a hint:
You need to use parallel arrays here. The first is the menu items themselves, the second is a "counter" or "distribution" array. The counter array would have 1 integer element (initialized to 0) for each menu item. Then, as the customer orders items, you increment the appropriate element in the counter array.
That should get you headed in the correct direction for now.
Basic idea:
const int RANGE = 8;
int inputValue = 0;
int distribution[RANGE] = {0};
cout << "Enter a number from 0 - " << RANGE - 1 << ": ";
cin >> inputValue;
while (inputValue >=0 && inputValue < RANGE) {
distribution[inputValue]++;
cout << "Enter a number from 0 - " << RANGE - 1 << ": ";
cin >> inputValue;
}
for (int i = 0; i < RANGE; i++) {
cout << i << " was entered " << distribution[i] << " times." << endl;
}
Fbody
Posting Maven
2,930 posts since Oct 2009
Reputation Points: 833
Solved Threads: 393