Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

simple black jack simulator

$
0
0
I'm working on a blackjack simulator and having some trouble. directions are as follow. there is a dealer and a player. if you go over 21 you lose. you may draw another card as many times as you want without going over. card values are ace = 1, j-k = 10. you can have dup cards so two king of spades IS possible. i'll put what I have so far below. Im working on randomizing the suit and face and just trying to output them on my main.cpp file. any tips or advice as to where I should go as of where I am would be helpful.

cpp file.
int main()
{
    srand(unsigned(time(NULL))); // makes random, random.
    
    BlackJack();
    getSuit();
    getFace();
    
    system ("PAUSE");//testing
    return 0;  
}
 .H file
#ifndef BLACKJACK_H
#define BLACKJACK_H
using namespace std;
class BlackJack
{
      private:
              char suit;
              string face;
              int value;
      public:
             BlackJack();
             
             void getSuit(int); // the getsuit and face are undeclared 
             void getFace(int); // not sure why
          
};
#endif

classes cpp file
BlackJack::BlackJack()
{
      int r_suit;
      int r_face;
      
      r_suit = rand() %4+1;
      r_face = rand() %13+1;
      
      cout << r_suit;
      cout << r_face;  // testing purposes
}
void BlackJack::getSuit(int r_suit) // this was a char
{

     char suit;
     
     if(r_suit = 1)
          suit = 'H';
     else
     if(r_suit = 2)
          suit = 'S';
     else
     if(r_suit = 3)
          suit = 'D';
     else
     if(r_suit = 4)
          suit = 'C';
     
     cout << suit << " "; // i was returning the suit
}
void BlackJack::getFace(int r_face) // this was a string
{
    
      string face;
      
      if(r_face >=2 && r_face <=10)
      
           face = r_face;    
      else
      
      if(r_face = 1)
           face = "Ace ";
      else
      if(r_face = 11)
           face = "Jack ";
      else
      if(r_face = 12)
           face = "Queen ";
      else
      if(r_face = 13)
           face = "King ";
      
      cout << face << " "; //was returning the string
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>