Hey there!
Summarizing the problem within the title is too hard but I tried.
Let's just jump right in!
I am pretty new (enough to only program in the console) to C++. Right now I am trying to code a hi-lo game. Where you guess if the next card is higher or lower than the current.
But my problem is that I want to use a function for simple access to the randomize function and I have 1 set up for the house and 1 for the card.
What the card one does is randomizing a value between 1 and 13. But what I want to do is that I want to return J instead of 11, Q instead of 12 etc.
My first idea was to just use a char as the card, as then it wouldn't matter if it's a 1, 5, J or A. But then if the random function gives me a 10 it will crash.
I don't know how I should do to make it as simple as possible. I was thinking about using a vector as I can just resize it if necessary. But maybe there's a different way?
Here's the code if you feel like you need to look at it :
int iRandomCard() {
int randomCard;
time_t t;
time(&t);
srand(t);
randomCard = rand()%13+1;
return randomCard;
}
void vStartGame() {
string house;
int card;
house = sRandomHouse();
card = iRandomCard();
}
(obviously using int won't work but that's just the code right now)
I tend to make posts long...
Help is appreciated!