Inventory PRoject

Well For my fundamentals of programming we have to do a
Fantasy RPG invetory FlowChart,Pseudocode and Code
I got stuck with code...
We got a source code and customized it a lil
problem is we are tryin to make a choice within a choice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Hero's Inventory
// Demonstrates arrays
// By rainbow78 at daniweb
//http://www.daniweb.com/forums/thread84020.html
#include <iostream>
#include <string>
#include <cmath>
#include<iomanip>
#include<ctime>

using namespace std;

const int MAX_ITEMS = 12;
const int MAX_ITEMS2 = 5;

int main()
{
 
   unsigned int health = 200; //health
   unsigned int mana = 100; //mana 

   string inventory[MAX_ITEMS];
   string inventory2 [MAX_ITEMS2];
   int numItems = 0; //always assign a value to new variables
   int choice=numItems;
   int numItems2=0;
   char another;
 
 cout << "Player is wearing Basic armor(Full leather armor,knife & Shield)." << endl;
 
 // begin loop
  do
{
 // list of items for input
 // Array list
inventory[0] = "Stamina";
inventory[1] = "Mana";
inventory[2] = "Eguipment";
inventory[3] = "Melee";
inventory[4] = "Range";
inventory[5] = "Support Spells";
inventory[6] = "Offensive Spells";

 
// list of items for user to pick/see
cout<< "\n\n"; 

cout<< "welcome to Fantsy RPG inventory!\n";
cout<<"1. Stamina\n";
cout<<"2. Mana\n";
cout<<"3. Eguipment\n";
cout<<"4. Melee\n";
cout<<"5. Range\n";
cout<<"6. Support Spells\n";
cout<<"7. Offensive Spells\n";


// inventory choice and health choice
cout<< "\n\n";
cout<< "please pick a item to add to your inventory\n";
cout<< "Regenerate +10 Stamina when remained on pause once.\n\n";  
 
   cin >> choice;



  inventory2[numItems2]=inventory[choice-1];
numItems2++;
    cout << "Your items:\n";
	
   if (numItems2 < MAX_ITEMS2)
   {
 
    for (int i = 0; i < numItems2; ++i)
 
 
    cout << inventory2[i] << endl;
    cout << inventory2[numItems2] << endl;
 

 
   }// end if
   else 
 
 
   cout << "You have too many items and can't carry another.";  // When Max is reached Output will show 
 
// end else
   // switch stament 
 switch(choice)
{
	case 1: 
		health++; // Health
		cout << health << endl; //test
	break;

	case 2: 
		mana++;  // Mana
		cout << mana << endl; //test
	break;

	case 3: // Eguipment
		cout<< " Plate Mail" << endl;
		cout<< " Mithril Armor" << endl;
		cout<< " Bronze Armor" << endl;
	break;

	case 4:  // Melee
		cout<< " Axe" << endl;
		cout<< " Club" << endl;
		cout<< " Broad sword" << endl;
   break;
	case 5:  // Range
		cout<< " CrossBow" << endl;
		cout<< " Ballista" << endl;
		cout<< " Throwing Knifes" << endl;
		cout<< " Throwing Spear" << endl;
	break;
	case 6:  // Support Spells
		cout<< " Heal Scroll" << endl;
		cout<< " Shield Scroll" << endl;
		cout<< " Haste Scroll" << endl;
    break;
	case 7:  // Offensive Spells
		cout<< " Fire Bolt scroll" << endl;
	    cout<< " Ice Bolt scroll" << endl;
		cout<< " Lightning Bolt scroll" << endl;
    break;

	default: cout << "thats not a choice idiot!";
}
 
//ending part of loop
  cout << "\n\n\nWould You Like To Play Again? (y/n): ";
cin >> another;
 
 }while(another == 'Y' || another == 'y') ;// loop
 
 
 
 return 0;
}//end main 

So when we run it on Visual studio and we got it running
I added the switch statement but when we debug it we wanna make it so you choose one of the weapons or eguipment
and itll show that you eguipped it
so at the end itll show all the eguipment you have eguipped
Any ideas on how to do...
I tried adding a If stament but didnt work
Please and Thank you.
Last edited on
Anyone?
For starters, you don't need
1
2
3
#include <cmath>
#include<iomanip>
#include<ctime> 


For your actual question, this should give you a good start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
	case 3: // Eguipment
		int i;
		cout<< "1) Plate Mail" << endl;
		cout<< "2) Mithril Armor" << endl;
		cout<< "3) Bronze Armor" << endl;
		cout<< "Choose one" << endl;
		do
		{
			cin >> i;
			switch (i)
			{
			case 1:
				cout << "You Equip the Plate Mail" << endl;
				break;
			case 2:
				cout << "You Equip the Mithril Armor" << endl;
				break;
			case 3:
				cout << "You Equip the Bronze Armor" << endl;
				break;
			default:
				cout << "Invalid choice. Try again" << endl;
			}
		}
		while ( i < 1 || i > 3 );
	break;

	case 4:  // Melee 


There are a million different ways to do this though.
default: cout << "thats not a choice idiot!";

lmfao..
@mackabee omg tyvm
didnt know if u could nest switch statements

the three header files you pointed out were cuzz i was thinking of adding a battle scene at the end

but wouldnt u have to declare it
Declare "it"? What do you mean?
This is more or less C programming style.
I suggest you to use C++ style rather than C style.
Use Object-Oriented concepts to eliminate that long switch statement.
Topic archived. No new replies allowed.