You do realise that line 40 makes absolutely no sense.
37 38 39 40 41 42
|
string Itemarray[3] { hammer.item_desc, nail.item_desc, wrench.item_desc };
cout << "Which item would you like to look at?" << endl;
int *line;
*line = &Itemarray[3];
cin >> *line;
cout << *line <<endl;
|
1. you integer pointer is uninitialized, so dereferencing it has a very good chance of blowing up; if not, you be setting some random bit of memory to an int value.
2. you're trying to set the value of the integer supposedly pointed to by your int* to the address of a row of a string array (which will be a string*)
3. the index you're using is the same size as the array, so it's referring to the element just beyond the extent of the array, which will either be junk or part of some other variable. Or cause the program to crash.
And that line 41 and 42 just read an int value and write it back out (if the pointer was referring to a valid memory address, that is.)
Being really perverse, this will compile
37 38 39 40 41 42 43 44 45
|
string Itemarray[3] { hammer.item_desc, nail.item_desc, wrench.item_desc };
cout << "Which item would you like to look at?" << endl;
int temp = 0; // somewhere to store int
int *index = &temp; // point at an existing int
//*line = &Itemarray[3];
cin >> *index; // should be checking this works!
string *line;
line = &Itemarray[*index]; // line not *line, and *index replaces 3
cout << *line <<endl;
|
But not that line 37 is actually using a C++11 feature, so if this works for you your compiler must have partial support at least for C++11.
Eliminating the pointless int* (it's only ever used by dereferencing it) and replacing string* with a reference, you get (basically the same as approach as Gamer2015 used):
37 38 39 40 41 42
|
string Itemarray[3] { hammer.item_desc, nail.item_desc, wrench.item_desc };
cout << "Which item would you like to look at?" << endl;
int index = 0;
cin >> index; // should be checking this works!
string& line = Itemarray[index]; // should be checking index in range
cout << line <<endl;
|
Of course, as I've already said, the index shouldn't be used without validation. Esp. in something like a game!
Andy