anonymous
  • anonymous
Can anyone help me with a c++ program I have to build a deck of cards ? and having some trouble...?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
osanseviero
  • osanseviero
What have you done until know?
anonymous
  • anonymous
hang on I'll try and upload my code...
1 Attachment
anonymous
  • anonymous
I 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?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Im just working on trying to fill the deck array for each card struct...
anonymous
  • anonymous
Could you at least hint to me how to fill the struct Card array with a for loop?
osanseviero
  • osanseviero
Well, 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
  • anonymous
Yes, 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
  • osanseviero
I think two fors are enough. One that creates each suit, another one that creates every card inside
osanseviero
  • osanseviero
Or explain me why 3 fors
anonymous
  • anonymous
Yes but how will I fill all 52 cards from "deck" array?
anonymous
  • anonymous
because each suit is supposed to have 13 card values 1 -13 for hearts, 1-13 for spades, etc. all the way to 52 cards...
anonymous
  • anonymous
but 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
  • anonymous
I 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
  • osanseviero
Do 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
  • osanseviero
I 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
  • anonymous
correct, going from 1-13, 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
  • osanseviero
You 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
  • anonymous
can you show me an example?
osanseviero
  • osanseviero
Mmm. i = 0 while i < 4 for(int idx=0; idx <= 13; idx ++) ADD IDX to ARRAY ENDFOR i = i + 1 ENDWHILE
osanseviero
  • osanseviero
How does that look for the creation of the array?
anonymous
  • anonymous
totally confusing. don't understand ?
anonymous
  • anonymous
im filling an array inside the struct?...
anonymous
  • anonymous
Well thanks for the help. But Im going to have to move on. Thank you ]

Looking for something else?

Not the answer you are looking for? Search for more explanations.