#include <vector>
#include <algorithm>
//...
vector<string> cards;
//...
void Random ()
{
//...
//After "RANDOM VALUE" (line 108)
//Before "DISPLAY" (line 113)
if ( count(cards.begin(),cards.end(),color_str+'\t'+value_str) )
{
//Values exists so repeat the function
Random();
return;
}else
{
//insert the value in the vector
cards.push_back(color_str+'\t'+value_str);
if ( cards.size()==52 ) cards.clear();//if it contains all the cards (which are 52) delete all vectors elements
}
//...
}
With these modifications your program shouldn't repeat until all the cards were given
I know I am extremely annoying but what exactly does cards.begin and cards.end calculate(what are their values =S)?
-EDIT-
What I meant is "Can you explain me this line in details so I won't have to bother ppl each time I have to use this... I would like to learn at beginning... if ( count(cards.begin(),cards.end(),color_str+'\t'+value_str) )
I've read all of those tuts and still don't get why do I have to write ( count(cards.begin(),cards.end() and not just color_str+'\t'+value_str) and compare it to...Well, something xD
The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements. A range is any sequence of objects that can be accessed through iterators or pointers, such as an array or an instance of some of the STL containers.
If you want to compare you will need a loop
eg:
1 2 3 4 5 6 7 8 9 10 11 12
for(unsigned i=0; i<cards.size(); i++)
if( cards[i] == color_str+'\t'+value_str )
{
Random();
return;
}
/*
as in the loop you have a return statement if it finds a value in cards
which is the same as color_str+'\t'+value_str the function will be stopped
and you won't get here, if Random will continue from here that means that
it wasn't found
*/
Ok ty and this is FINALLY totally done! *phew* xD
This is my last question in this thread I swear...
What does this mean? cards.push_back(color_str+'\t'+value_str);
Ok sry this could be closed now...
I've read that vector tutorial once more and now i understand it all.
I would like to thank once more to everyone who helped me. =)