I am a bit confused. I am trying to make a program that will take the choices you make and display them all simular to this:

Item 1. Sword
Item 2. Shield
Item 3. Potion
Item 4. Potion

but when I try to run it it looks more like this
first
Item 1. Sword

then
Item 1. Shield
Item 2. Shield

then
Item 1. Potion
Item 2. Potion
Item 3. Potion

and so on and so forth. I am unsure of what i am doing wrong.

#include <iostream>
#include <iomanip>

using namespace std;
const int NumItems = 7;
const int StringSize = 8;
int choice = 0,
    Shown=0,
    count = 0,
    inList=0; 
     
int main()
{
  int YesNo = 1;
  double count = 0;
  cout << "Welcome to the inn, before you set out on your adventure, \nyou'd best "
       << "gather your equipment. \nWould you like to pack something?\n 1. Yes\n 2. No\n";
  cin >> YesNo;
  while (YesNo != 2)
  {
    count++;
    cout << "Ok what would you like to pack?\n";
    cout << " 1. Sword \n 2. Shield \n 3. Helmet \n 4. Armor \n 5. Potion \n 6. Ether \n 7. Elixir\n";
     cin >> choice;
     
     char Items[NumItems][StringSize] =
          { "Sword", "Shield", "Helmet", "Armor", 
            "Potion", "Ether", "Elixir"};

            
     if ((choice != 1) && (choice != 2) && (choice != 3) &&
         (choice != 4) && (choice != 5) && (choice != 6) && (choice != 7))
     {
      cout << "I'm sorry, what was that? ";
      cin >> choice;
     }
    cout << "alright, i'll put one in your pack. \n"
         << "Your pack contains the following: \n";
    for (int index = 0; index < count; index++)
    {
        cout << "item " << (index + 1) << ". " << Items[choice-1] << endl;

    }  
    cout << "Would you like to pack anything else?\n";
    cin >> YesNo;
    }


  system ("pause");
  return 0;                 
}

please help if you can.

You aren't storing the items anywhere?

All you are doing is increasing the number of items bought each time. And printing the latest item off.

If you buy item 5, 6 and 1. You need to store this somewhere, maybe in another array? Then print out this array. Not the itemlist array.

Currently this is what you are doing:

Add Item? - Yes
Increase numItems
Which Item? - x
FOR LOOP - FOR numItems, print out Item x

What you want is:

Add Item? - Yes
Which Item? - Item = 2
Bag[numItems] = Item
numItems++
for(i = 0; i < numItems; i++) .... print Bag

Ok, i see what you mean. but it doent seem to be working, maybe i am not writing it correctly. here's what i'm trying:

char Items[NumItems][StringSize] =
          { "Sword", "Shield", "Helmet", "Armor", 
            "Potion", "Ether", "Elixir"};

        Bag[inList]=Items;
            inList++;
     if ((choice != 1) && (choice != 2) && (choice != 3) &&
         (choice != 4) && (choice != 5) && (choice != 6) && (choice != 7))
     {
      cout << "I'm sorry, what was that? ";
      cin >> choice;
     }
    cout << "alright, i'll put one in your pack. \n"
         << "Your pack contains the following: \n";
    for (int index = 0; index < inList; index++)
    {
        cout << "item " << (index + 1) << ". " << Bag[index] << endl;

    }  
    cout << "Would you like to pack anything else?\n";
    cin >> YesNo;
    }
#include <iostream>
#include <iomanip>

using namespace std;
const int NumItems = 7;
int numOfUserItems = 0;
char userItems[10]; //max of 10 items per user
const int StringSize = 8;
int choice = 0,
    Shown=0,
    count = 0,
    inList=0; 
     
int main()
{
  int YesNo = 1;
  double count = 0;
  cout << "Welcome to the inn, before you set out on your adventure, \nyou'd best "
       << "gather your equipment. \nWould you like to pack something?\n 1. Yes\n 2. No\n";
  cin >> YesNo;
  while (YesNo != 2)
  {
    cout << "Ok what would you like to pack?\n";
    cout << " 1. Sword \n 2. Shield \n 3. Helmet \n 4. Armor \n 5. Potion \n 6. Ether \n 7. Elixir\n";
     cin >> choice;
     
     char Items[NumItems][StringSize] =
          { "Sword", "Shield", "Helmet", "Armor", 
            "Potion", "Ether", "Elixir"};

            
     if ((choice != 1) && (choice != 2) && (choice != 3) &&
         (choice != 4) && (choice != 5) && (choice != 6) && (choice != 7))
     {
      cout << "I'm sorry, what was that? ";
      cin >> choice;
	 } else { 
	userItems[numOfUserItems] = choice;
    cout << "alright, i'll put one in your pack. \n"
	 }
         << "Your pack contains the following: \n";
    for (int index = 0; index < numOfUserItems; index++)
    {
        cout << "item " << (index + 1) << ". " << Items[userItems[index]] << endl;

    }  
    cout << "Would you like to pack anything else?\n";
    cin >> YesNo;
    }


  system ("pause");
  return 0;                 
}

Try it. I am eating dinner in a min so cba :)

Im sorry to say it, butwhen I pasted your program to my compiler, i had the same problem when i started. Have you any other thoughts? please.

#include <iostream>
#include <iomanip>

using namespace std;
const int NumItems = 7;
int numOfUserItems = 0;
char userItems[10]; //max of 10 items per user
const int StringSize = 8;
int choice = 0, Shown=0, count = 0, inList=0; 

int main()
{
	int YesNo = 1;
	double count = 0;
	cout << "Welcome to the inn, before you set out on your adventure, \nyou'd best "
		<< "gather your equipment. \nWould you like to pack something?\n 1. Yes\n 2. No\n";
	cin >> YesNo;
	while (YesNo != 2)
	{
		cout << "Ok what would you like to pack?\n";
		cout << " 1. Sword \n 2. Shield \n 3. Helmet \n 4. Armor \n 5. Potion \n 6. Ether \n 7. Elixir\n";
		cin >> choice;

		char Items[NumItems][StringSize] =
			{ "Sword", "Shield", "Helmet", "Armor", 
				"Potion", "Ether", "Elixir"};


		if ((choice != 1) && (choice != 2) && (choice != 3) &&
		(choice != 4) && (choice != 5) && (choice != 6) && (choice != 7))
		{
			cout << "I'm sorry, what was that? ";
			cin >> choice;
		} else { 
			userItems[numOfUserItems] = (choice-1);
			cout << "alright, i'll put one in your pack. \n";
		}
		cout << "Your pack contains the following: \n";
		numOfUserItems++;
		for (int index = 0; index < numOfUserItems; index++)
		{
			cout << "item " << (index + 1) << ". " << Items[userItems[index]] << endl;
		}  
		cout << "Would you like to pack anything else?\n";
		cin >> YesNo;
	}
	system ("pause");
	return 0;                 
}

Done.

However you should look over this, I'm new with C++ but fixed it in 2min. I was missing a brace or 2 and a variable++.

Ah Ha! it works, you have my thanks.
The bunny thanks you too. 8D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.