need debugging help.. i've look at this too long

Thread Solved

Join Date: Jun 2006
Posts: 25
Reputation: hoosier23 is an unknown quantity at this point 
Solved Threads: 1
hoosier23 hoosier23 is offline Offline
Light Poster

need debugging help.. i've look at this too long

 
1
  #1
Sep 23rd, 2006
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

  1. #ifndef PLAYER_H
  2. #define PLAYER_H
  3.  
  4. using namespace std;
  5.  
  6. class player
  7. {
  8. private:
  9. char* name;
  10. int bankroll = 1000;
  11. int bet = 100;
  12. public:
  13. void add_name(char *ip1)
  14. {
  15. name=new char[10]; strcpy(name,ip1);
  16. }
  17. char* getname() {return name;}
  18. int betting(int betRef, int bankrollRef)
  19. {
  20. cout << "Bank Roll: $" << bankrollRef << endl;
  21. cout << "You Bet: $" << betRef << ". " << "You have $" << bankrollRef - betRef << " left.\n";
  22. if (bankrollRef == '0')
  23. {
  24. cout << "\n You're BROKE!";
  25. }
  26.  
  27. return bankrollRef, betRef;
  28. }
  29. };
  30. #endif

this is my practice.cpp

  1. #include <iostream>
  2. #include <algorithm>
  3. #include "player.h"
  4.  
  5. using namespace::std;
  6. using std::random_shuffle;
  7.  
  8. int main()
  9. {
  10. //general directions for a user-friendly interface
  11.  
  12. cout << "Welcome to the Blackjack Game!\n" << endl;
  13. cout << " Directions:\n" << endl;
  14. cout << " You may ask the dealer to:" << endl;
  15. cout << " (H) Hit \n (S) Stand \n (D) Double Down" << endl;
  16. cout << " (?) Show Deck\n (Q) Quit\n\n" << endl;
  17. cout << "=============================================\n" << endl;
  18.  
  19. player s1;
  20. cout << endl;
  21. cout << "Please enter your name: ";
  22. cin >> s1.add_name(" ");
  23. cout << "Welcome: " << s1.getname() << endl;
  24.  
  25. player::betting;
  26.  
  27. //if statements that responds to user input
  28.  
  29. // int selection;
  30. //
  31. // if (selection == 'H' || 'h')
  32. // do this
  33. // if (selection == 'S' || 's')
  34. // do this
  35. // if (selection == 'D' || 'd')
  36. // do this
  37. // if (selection == '?')
  38. // do this
  39. // else (selection == 'Q' || 'q')
  40. // {
  41. // break;
  42. // }
  43. //
  44.  
  45. char cards[13]={'2','3','4','5','6','7','8','9','0','J','Q','K','A'};
  46. char deck [260];
  47. for (int i=0; i< 260; i++)
  48. deck[i] = cards [i % 13];
  49.  
  50. random_shuffle(deck, deck+260); //researched random shuffle on http://gethelp.devx.com/techtips/cpp_pro/10min/10min1299.asp
  51. random_shuffle(deck, deck+260); //use this function to shuffle again
  52.  
  53. int selection;
  54.  
  55. if(selection == '?')
  56. {
  57. for (int i = 0; i < 260; ++i)
  58. cout << deck[i];
  59. system("PAUSE");
  60. }
  61. cin >> selection;
  62. return 0;
  63. }

thank you if you are able to help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,321
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 384
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: need debugging help.. i've look at this too long

 
1
  #2
Sep 24th, 2006
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:-
  1. void add_name(char *ip1)
  2. {
  3. name=new char[10]; strcpy(name,ip1);
  4. }

would become:-

  1. void add_name(string ip1)
  2. {
  3. name = ip1;
  4. }
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1019 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC