| | |
need debugging help.. i've look at this too long
Thread Solved |
•
•
Join Date: Jun 2006
Posts: 25
Reputation:
Solved Threads: 1
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
this is my practice.cpp
thank you if you are able to help!
this is
player.h
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
#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!
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:-
would become:-
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.
1. Instead of using const char arrays try using std::strings.
They afford greater flexibility and are easier to read. For example this:-
C++ Syntax (Toggle Plain Text)
void add_name(char *ip1) { name=new char[10]; strcpy(name,ip1); }
would become:-
C++ Syntax (Toggle Plain Text)
void add_name(string ip1) { name = ip1; }
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.
*Voted best profile in the world*
![]() |
Similar Threads
- Best C++ compiler (C++)
- How long do you use your computer each day? (Geeks' Lounge)
- Windows XP takes too long to start up (Windows NT / 2000 / XP)
- Sooo ... how long do you think this style will last?! (DaniWeb Community Feedback)
- windows long horn beta edition... (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: create, write & read file to/from folder
- Next Thread: [Linker error] undefined reference to `CQTMovieFile::CQTMovieFile()'
Views: 1019 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count data delete desktop display dll dynamic encryption error exception file files fstream function functions game givemetehcodez graph graphics gui homework http iamthwee input int lazy linker list loop looping loops math matrix member memory multidimensional newbie number numbers object objects opengl output parameter pointer pointers problem program programming project python random read reading recursion recursive reference sort sorting spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual visualstudio win32 window windows winsock xml






