A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 one year ago
Can anyone help me with a c++ program I have to build a deck of cards ? and having some trouble...?
anonymous
 one year ago
Can anyone help me with a c++ program I have to build a deck of cards ? and having some trouble...?

This Question is Open

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0What have you done until know?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0hang on I'll try and upload my code...

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0I don't understand how I'm supposed to create a function that fills the "Card" struct for each card?.. do I have to use a for loop? but if so, how do I iterate it?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Im just working on trying to fill the deck array for each card struct...

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Could you at least hint to me how to fill the struct Card array with a for loop?

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0Well, you know you want 52 cards. There are four suits and 13 cards for each suit. I'll just talk about the logic. There are several ways to do this. One way is to do an array of arrays. So you have 4 arrays, each with 13 cards. Something like: array = [['A', 2, 3 ,4...'K'], ['A', 2, 3 ,4...'K'], ['A', 2, 3 ,4...'K'], ['A', 2, 3 ,4...'K']]. Then, when you use it, you know that array[0] refers to a specific suit. The problem with this will come when you shuffle the deck, so I don't think this is the best way. Another way is to simply create an array of ['A','A','A','A'...'K','K'] and another array with the suits [1,2,3,4,1,2,3,4,1,2,3,4...3,4] and when you shuffle it, do the same to both arrays. You could even have an array suites = {1,2,3,4} and array faces = {1,2,3,4,5,6,7,8,9,10,11,12} and then work around it when shuffling Sorry for the syntax errors, I was just trying to cover the logic.

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Yes, the last method you talked about is how I am trying to approach it.. I understand that the suits and faces are inside the "Card" struct. But I'm not understanding how to create the for loops to match the integer to the suit?... because the I created an array of structs from Card ; called Card deck[52]; but I don't know how which loop to start with to fill it. Do i create the first loop, like, for(int i = 0; i < deck; i++) nested with another for loop; for(int k=0; k < suit; k++) nested with another for loop; for(int j =0; j < value; j++); deck[j] = j; ?

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0I think two fors are enough. One that creates each suit, another one that creates every card inside

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0Or explain me why 3 fors

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Yes but how will I fill all 52 cards from "deck" array?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0because each suit is supposed to have 13 card values 1 13 for hearts, 113 for spades, etc. all the way to 52 cards...

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0but If I create an array called deck[52]. from the struct CARD... how do I first "set" the deck with each value assigned to each suit?... ensuring i'm using all numbers up to 52. ?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0I don't know exactly how many for loops I would have to use but in what order do I assign the element. I don't even know how to start?

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0Do you want to repeat 4 times the same numbers, or go from 1 to 52 and just sat that from 1 to 13 is suit a, then from 14 to 26 I'm talking about suit b, etc

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0I just thought that you could simply do an array from 1 to 52, with those numbers. And with modulus and ranges it would work

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0correct, going from 113, then 14 26, for b etc. is how I want to do it. If I just stripped all the other junk away from my code and just started with my struct Card, my "deck array" (deck[52]), and my function to fill the array (bool set_deck(Card[]) ... and I start in my main and pass "deck" as my array value into set_deck(Card[]).. what for loop would I build first?

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0You can do it perfectly fine with 1 for loop that gets the values from 1 to 12, and repeat that loop 4 times. You can do it with while, too

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0can you show me an example?

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0Mmm. i = 0 while i < 4 for(int idx=0; idx <= 13; idx ++) ADD IDX to ARRAY ENDFOR i = i + 1 ENDWHILE

osanseviero
 one year ago
Best ResponseYou've already chosen the best response.0How does that look for the creation of the array?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0totally confusing. don't understand ?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0im filling an array inside the struct?...

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0Well thanks for the help. But Im going to have to move on. Thank you ]
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.