final project for class

here is the updated version of the code, btw I transfer object into inventory because one is the item and the other is the inventory of the person after having purchased the item at hand.

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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include <string>
using namespace std;


class Item 
{
	public: int cost;
	string name;
	string description;

	// constructor
		public: Item (int cost, string name, string description)
	{
		cost = cost;
		name = name;
		description = description;
	}
};

int main (void)
{
	int choice =0;
	int num =0;
	Item* object[100];

	object[0] = new Item(10, "Acid flask", "A flask filled with acid to use situationally.");
	object[1] = new Item(15, "Alchemist fire", "A flask filled with a combustable gel.");
	object[2] = new Item(10, "Bottled Torch", "A bottle filled with light.");
	object[3] = new Item(5, "Bottle of cure disease", "A bottle of ground herbs to fight off diseases.");
	object[4] = new Item(15, "Bottle of healing powder", "A bottle of ground herbs to heal scrapes and burns.");
	object[5] = new Item(10, "Bottle of remove poison", "A bottle of ground herbs to remove poison.");
	object[6] = new Item(20, "Healing potion", "A magical potion used to heal deep wounds.");
	object[7] = new Item(25, "Potion of swiftness", "A magical potion which increases ones speed temporarily.");
	object[8] = new Item(50, "Potion of true ressurection", "A magical potion which has the power to bring back to recently deceased.");

	int inventory [100];
	int invTot= 0;
	int credits= 100;

	cout << "Welcome to the potion shop. We currently are limited on our inventory please pick from our reserves." << endl;
	cout << "This is what we currently have." << endl;
	cout << '1' << object[0]->cost << object[0]->name << object[0]->description << endl;
	cout << '2' << object[1]->cost << object[1]->name << object[1]->description << endl;
	cout << '3' << object[2]->cost << object[2]->name << object[2]->description << endl;
	cout << '4' << object[3]->cost << object[3]->name << object[3]->description << endl;
	cout << '5' << object[4]->cost << object[4]->name << object[4]->description << endl;
	cout << '6' << object[5]->cost << object[5]->name << object[5]->description << endl;
	cout << '7' << object[6]->cost << object[6]->name << object[6]->description << endl;
	cout << '8' << object[7]->cost << object[7]->name << object[7]->description << endl;
	cout << '9' << object[8]->cost << object[8]->name << object[8]->description << endl;

	switch (num) // outputs number of which item is being purchased.
	{
		case 1:  object [0]
		{
			cout << object[0]->cost, << object[0]->name, << object[0]->description << endl;
			object [0] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = object[0](cost)- credits;
			}
			break;
		}
		case 2: object [1]
		{
			cout << object[1]->cost << object[1]->name << object[1]->description << endl;
			object [1] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[0]->cost;
			}
			break;
		}
		case 3: object [2]
		{
			cout << object[2]->cost << object[2]->name << object[2]->description << endl;
			object[2] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[2](cost);
			}
			break;
		}
		case 4: object [3]
		{
			cout << object[3]->cost << object[3]->name << object[3]->description << endl;
			object [3] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[3](cost);
			}
			break;
		}
		case 5: object [4]
		{
			cout << object[4]->cost << object[4]->name << object[4]->description << endl;
			object[4] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[4](cost);
			}
			break;
		}
		case 6: object[5]
		{
			cout << object[5]->cost << object[5]->name << object[5]->description << endl;
			object[5] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[5](cost);
			}
			break;
		}
		case 7: object[6]
		{
			cout << object[6]->cost << object[6]->name << object[6]->description << endl;
			object[6] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[6](cost);
			}
			break;
		}
		case 8: object[7]
		{
			cout << object[7]->cost << object[7]->name << object[7]->description << endl;
			object[7] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits- object[7](cost);
			}
			break;
		}
		case 9: object[8]
		{
			cout << object[8]->cost << object[8]->name << object[8]->description << endl;
			object[8] = inventory[i];
			for (int i=0, i<invTot, i++)
			{
				cout << "You are carrying " << object[inventory[i]]->name;
				credits = credits - object[8](cost)
			}
			break;
		}
		default;
		{
			break;
		}
	}
	system ("PAUSE");
}
}
Last edited on
All of your for loops. You're leaving out the type in front of i.
Lines 43-51: These lines are begging for a loop.

All case labels: What is with the syntax here?
1
2
 
  case 1:  object [0]

object[n] is not a valid statement.

Every one of your cases is exactly the same except for the index (which is num-1). Why even have a switch statement?

Line 58, et el: What's the point of assigning inventory[i] to object[0]? You going to overwrite the object you created at line 27. Memory leak.
Objects are different types. You can't assign them.

Line 59, et al: Where is i defined? The correct separator is ; not ,
invTot is uninitialized.

Line 61, et el: object[0] is a pointer. You need to use -> not .

Line 62, et al: This syntax is bogus. Should be:
 
  credits = credits - object[0]->cost;


Line 150: missing ;

Line 154: Don't put case in front of default.
Last edited on
Topic archived. No new replies allowed.