need some help

Reply

Join Date: Sep 2008
Posts: 9
Reputation: cerb63 is an unknown quantity at this point 
Solved Threads: 0
cerb63 cerb63 is offline Offline
Newbie Poster

need some help

 
0
  #1
Oct 14th, 2008
I need some help trying to figure out the void statements for my project and also getting this second program Factorial Program without recursion to work right.
  1. #include <iostream>
  2. #include "PROJECT_13_1_H.h"
  3.  
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8. bool houseHasBigAce = false;
  9. srand(time(0));
  10. int houseHand = drawOpenHouseCard(houseHasBigAce);
  11.  
  12. cout<<endl<<endl;
  13. cout<<"Welcome to the game of BlackJack!"<<endl;
  14. cout<<"*********************************"<<endl<<endl;
  15.  
  16. int playerHand = buildPlayerHand();
  17. announceResult(PLAYER_SIDE, playerHand);
  18.  
  19. if (playerHand <=21)
  20. {
  21. houseHand = buildHouseHand(houseHand, houseHasBigAce);
  22. announceResult(HOUSE_SIDE, houseHand);
  23. }
  24. whoWins(playerHand, houseHand);
  25. system("pause");
  26. return 0;
  27. }
  28. int buildPlayerHand()
  29. {
  30. int theHand = 0;
  31. bool hasBigAce = false;
  32.  
  33. cout<<"The dealer will now deal cards to the player..."<<endl;
  34. for (int i=0; i<2; i++)
  35. {
  36. theHand= drawAndAddCardToHand(theHand, hasBigAce);
  37. }
  38. bool playerHolds = false;
  39. while (theHand < 21 && !playerHolds)
  40. {
  41. playerHolds = isPlayerHolding(theHand);
  42. if(!playerHolds)
  43. theHand = drawAndAddCardToHand(theHand, hasBigAce);
  44. }
  45. return theHand;
  46. }
  47. bool isPlayerHolding(int theHand)
  48. {
  49. char answer;
  50. cout<<"Do you wish to hold on "<<theHand<<"? Type Y - for Yes or N - for No."<<endl;
  51. do
  52. {
  53. cin>>answer;
  54. answer = toupper(answer);
  55. }while (answer != 'Y' && answer != 'N');
  56. return (answer == 'Y');
  57. }
  58. int drawOpenHouseCard(bool & hasBigAce)
  59. {
  60. cout<<"The dealer will draw an open card for the house"<<endl;
  61. return(drawAndAddCardToHand(0, hasBigAce));
  62. }
  63. int buildHouseHand(int theHand, bool & hasBigAce)
  64. {
  65. while (theHand < 17)
  66. {
  67. cout<<"The house draws on "<<theHand<<" and receives "<<endl;
  68. theHand = drawAndAddCardToHand(theHand,hasBigAce);
  69. }
  70. return theHand;
  71. }
  72.  
  73. int drawAndAddCardToHand(int theHand, bool &hasBigAce)
  74. {
  75. int theCard = drawOneCard();
  76. announceCard(theCard);
  77. theHand = addCardToHand(theHand, theCard, hasBigAce);
  78. announceHand(theHand);
  79. return theHand;
  80. }
  81. int drawOneCard()
  82. {return (rand() % 13 + 1);}
  83.  
  84. int addCardToHand(int theHand, int theCard, bool &handContainsAce11)
  85. {
  86. if (theCard > 10)
  87. theHand +=10;
  88. else
  89. if(theCard ==1 && theHand < 10)
  90. { theHand += 11;
  91. handContainsAce11=true;
  92. }
  93. else
  94. theHand+=theCard;
  95.  
  96. if (theHand > 21 & handContainsAce11)
  97. {
  98. theHand -=10;
  99. handContainsAce11 = false;
  100. }
  101. return theHand;
  102. }
  103.  
  104. //void announceCard(int);
  105. //void announceHand(int);
  106. //void announceResult(bool, int);
  107. //void whoWins(int, int);
second program
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int find_fib(int);
  5.  
  6. int main(int argc, char* argv[])
  7. {
  8. int n=0, result=0;
  9. cout << "Enter the position in the sequence to find: ";
  10. cin >> n;
  11. result = find_fib( n );
  12. cout << result << " is the " << n << "th Fibonacci sequence number" << endl;
  13. system("pause");
  14. return 0;
  15. }
  16.  
  17. int find_fib( int n )
  18. {
  19. if(n < 3)
  20. return 1;
  21. else
  22. return( find_fib(n - 2) + find_fib( n - 1 ) );
  23. }
Last edited by Narue; Oct 15th, 2008 at 9:18 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC