Hi need some help with this half attempt at a deal or no deal game
I would appreciate your help very much the problem is in the comments.

#include <iostream>
#include <vector>

using namespace std;

const int n_suitcase = 26;

struct Suitcase{
	int money_val;
};

//hold the list of suitcase obj 
vector<Suitcase> Mysuitcases;
vector<Suitcase>::iterator it; 

//function proto
void Sort_case(Suitcase &cases);
void Show_cases();

//get val inside each suitcase
int Get_val(vector<Suitcase> a,int box_id)
{
	//how do i return the val of the suitcase money_val member ? 
	
	return ?????????
}

void Remove_suitcase(int box_id)
{
//how do i remove the specified suitcase object from the vector without disturding the others or effecting the size of the vector ?

}


int main()
{	//create suitcases
	Suitcase suitcase[n_suitcase]; 

	//fill each suitcase with a money val and push back obj into vector
for(int a=0;a<n_suitcase;a++)
{
Sort_case(suitcase[a]);
Mysuitcases.push_back(suitcase[a]);
}

Show_cases();

cin.get();
	return 0;
}

void Sort_case(Suitcase &cases)
{

cases.money_val = 100;
}

void Show_cases()
{

it = Mysuitcases.begin();

 for ( it=Mysuitcases.begin() ; it < Mysuitcases.end(); it++ )
    cout << " " << *it;

}

When i complie this i get
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Suitcase' in the showcase function any idea why ?

int Get_val(vector<Suitcase> a,int box_id)
{
	//how do i return the val of the suitcase money_val member ? 
	
	return ?????????
}

How about something like:

int Get_val(vector<Suitcase> a,int box_id)
{
	return a.at(box_id);
}

And for deletion, you might want to check out the memberfunction erase()

You might also want to read a tutorial to learn a bit more about using a vector.

When i complie this i get
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Suitcase' in the showcase function any idea why ?

Yes. This line is giving you trouble: cout << " " << *it; You're passing an entire struct to cout and it doesn't know what to do with it. You should could the struct one member at a time.

If you want to remove an element and not reduce the size of the vector, erase() is not an option. You can have a vector of pointers of Suitcases and point the pointer to 0 (after freeing the memory of the element, if necessary) at the wanted position.

You can also write an operator<<() for your struct. It is more elegant to print the content this way instead of taking the elements of the struct one by one in your code.

See operator[] for returning an element in the vector.

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.