Started to try c++ again with a simple card game. I made a class for each card with two constructors, one with no values creates the card randomly and one that takes in values.
#include <string>
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <ctime>
#include <sstream>
class Card
{
private:
char suit;
int value;
public:
Card();
Card(char suit, int value);
void SetSuit(char suit);
void SetValue(int value);
...
std::string GetCard() ;
};
Card::Card(char suit, int value)
{
suit= toupper(suit);
this -> suit=suit;
this -> value=value;
}
Card::Card() //create random card
{
srand (time(0));
char suits [4] = {'D','S','H','C'};
int randNum = (rand() % 4);
SetSuit(suits[randNum]);
randNum = (rand() % 12)+2;
SetValue(randNum);
...
std::string Card::GetCard(){
...
return card.str();
}
If I create an array of card objects and then output it every card in the array has the same suit and value. I'm not sure how to get each card to be random the array.