I just need some help with showing me why I sometimes get the same card over again. When I have declared them and also done a if statement if the variable had been used before.
So what's the problem.
- I want a unique card to only show once, only one red king, only one red ten and so on.
I don't see what the error is, but in general, this is not the best approach.
If you want to have a random sequence, literally, have a random sequence. Declare a struct Card{ int farg, varde; }; (I'm just guessing what those words mean). Declare an array of 52 Cards and fill it in a for loop. Then use std::random_shuffle (defined in <algorithm>) to shuffle the deck. Finally have an integer which marks the top of the deck and move it every time you draw a card.
Yeah but I'm doing a school project so I haven't learned all the things you said there =)
Well of course I can compile it an run it, but I for example get red king more than 1 time when it's not supposed to, when I only want it 1 time. It's like it doesn't check the list or something :)
The algorithm to check whether a card has been played, is not vary simple (not the way you do it right now anyway). What if you roll farg = 0 but all hjarter cards have already been drawn? You'll get stuck in an infinite loop.
You could do like I said. If you don't understand something about that method, ask.
Another way, more similar to yours would be to generate a single random number 'i' with rand()%52. Have an array 'deck' of 52 booleans. Regenerate 'i' in a loop until deck[i] is false (just like you do now). When you do that, 'i' will be the index of a unique card. then farg = i/13 and varde = i%13. After that you can do with farg and varde whatever you need without any kind of checking.