Question
C++ error error: hand was not declared in this scope; I'm very new in C++ and I've tried different ways of declaring 'hand' but I
C++ error error: hand was not declared in this scope;" I'm very new in C++ and I've tried different ways of declaring 'hand' but I keep getting the above error. Can you please tell me how to fix this small issue in main()? Code:
cards gen_deck_of_cards()
{
cards retval;
for (card_faces f(card_faces_begin), fEnd; f != fEnd; ++f)
for (card_suits s(card_suits_begin), sEnd; s != sEnd; ++s)
retval.push_back(card{*f,*s});
return retval;
}
//function that shuffles the deck of cards
void shuffle_cards(cards& cs)
{
std::random_device rd;
std::mt19937 gen(rd());
std::shuffle (cs.begin(), cs.end(), gen);
}
//function that draws 'N' cards from the deck
cards draw (std::size_t num, cards& deck)
{
auto pos = deck.begin();
if (num <= deck.size())
{
std::advance(pos, num);
}
pos = deck.end();
cards(deck.begin(), pos);
deck.erase(deck.begin(), pos);
return cards();
}
int main()
{
cards deck;
//generates a deck of cards
deck = gen_deck_of_cards();
//shuffles the deck of cards
shuffle_cards(deck);
//prints out the deck of cards
std::cout << "Deck: ";
copy(deck.begin(), deck.end(), std::ostream_iterator(std::cout," "));
std::cout << " " << "Drawing 3 cards... ";
//draws 3 cards from the deck
hand = draw(3,deck);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started