i'm very much a newbie, so pardon me if i am breaking programmer ettiquette, but could someone debug this, please? i could use a lift after 8+ hours workin on this...

this is

player.h

#ifndef PLAYER_H 
#define PLAYER_H

using namespace std;

class player 
{
private:
        char* name;
        int bankroll = 1000;
        int bet = 100;
public:
    void add_name(char *ip1)
    {
        name=new char[10]; strcpy(name,ip1);
    }
    char* getname() {return name;}
    int betting(int betRef, int bankrollRef)
    {
        cout << "Bank Roll: $" << bankrollRef << endl;
        cout << "You Bet: $" << betRef << ". " << "You have $" << bankrollRef - betRef << " left.\n";
        if (bankrollRef == '0')
        {    
        cout << "\n You're BROKE!";
        }
    
        return bankrollRef, betRef;
    }
};
#endif

this is my practice.cpp

#include <iostream>
#include <algorithm>
#include "player.h"

using namespace::std;
using std::random_shuffle;

int main()
{
    //general directions for a user-friendly interface
    
    cout << "Welcome to the Blackjack Game!\n" << endl;
    cout << "     Directions:\n" << endl;
    cout << "       You may ask the dealer to:" << endl;
    cout << "         (H) Hit \n         (S) Stand \n         (D) Double Down" << endl;
    cout << "         (?) Show Deck\n         (Q) Quit\n\n" << endl;
    cout << "=============================================\n" << endl;

    player s1;
    cout << endl;
    cout << "Please enter your name: ";
    cin >> s1.add_name("  ");
    cout << "Welcome: " << s1.getname() << endl;
    
    player::betting;
        
    //if statements that responds to user input
    
    //    int selection;
    //
    //    if (selection == 'H' || 'h')
    //        do this
    //    if (selection == 'S' || 's')
    //        do this
    //    if (selection == 'D' || 'd')
    //        do this
    //    if (selection == '?')
    //        do this
    //    else (selection == 'Q' || 'q')
    //        {
    //        break;
    //        }
    //
    
    char cards[13]={'2','3','4','5','6','7','8','9','0','J','Q','K','A'};
    char deck [260];    
    for (int i=0; i< 260; i++)
        deck[i] = cards [i % 13]; 
    
    random_shuffle(deck, deck+260);   //researched random shuffle on http://gethelp.devx.com/techtips/cpp_pro/10min/10min1299.asp
    random_shuffle(deck, deck+260);  //use this function to shuffle again

    int selection;

    if(selection == '?')
    {
        for (int i = 0; i < 260; ++i)
        cout << deck[i];
        system("PAUSE");
    }
    cin >> selection;
    return 0;
}

thank you if you are able to help!

Member Avatar for iamthwee

Just a few pointers. I've noticed you have marked this thread as solved so I assume everything is working ok.

1. Instead of using const char arrays try using std::strings.
They afford greater flexibility and are easier to read. For example this:-

void add_name(char *ip1)
    {
        name=new char[10]; strcpy(name,ip1);
    }

would become:-

void add_name(string ip1)
{
   name = ip1;
}

Much easier I think you'll agree.

Additionally, you shouldn't be using system("PAUSE"); to pause your program. There are many reasons why, if you do a search you will find them. Instead you could use a few cin.get(); to pause the program. There are even better ways but I find that one the easiest.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.