944,185 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3481
  • C++ RSS
Sep 4th, 2004
0

Craps, game help!

Expand Post »
I've been studying VC++ for about 2 months, and I was working on my first game from a book (Game Programming All In One)
The game is 'Craps', it's a dice game. Anyways, I've had a few prolems with the codeing, can someone help me? (Windows 32 Console)
Here is the game....


C++ Syntax (Toggle Plain Text)
  1. #include <iostream> // Includeing Headers
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std; // Language
  6. // Global Variables
  7. void ShowIntroScreen (void), ShowInformation (unsigned long Money);
  8. short GetBet (void), DoDiceThrow (void);
  9. unsigned short DoMoneyCalc (short Dice, short Bet, short BetMoney);
  10. unsigned long GetAmount (void);
  11.  
  12. main (void)
  13. {
  14. unsigned long MoneyEarned, Money;
  15. short DiceValue, Bet, BetMoney;
  16.  
  17.  
  18. ShowIntroScreen ();
  19. Money = 1000;
  20.  
  21. do // Loop Actions
  22. {
  23. ShowInformation (Money);
  24.  
  25. Bet = GetBet ();
  26. BetMoney = GetAmount ();
  27. DiceValue = DoDiceThrow ();
  28. MoneyEarned = DoMoneyCalc (DiceValue, Bet, BetMoney);
  29.  
  30. Money -= BetMoney;
  31.  
  32. if (MoneyEarned == 0 )
  33. {
  34. cout << "You have lost. The number was: " << DiceValue << endl << endl;
  35. }
  36. else
  37. {
  38. cout << "You won " << MoneyEarned - BetMoney;
  39. cout << " dollars. Number was: " << DiceValue;
  40. cout << endl << endl;
  41.  
  42. Money += MoneyEarned;
  43. }
  44. }
  45. while (Money > 100);
  46. cout << "Game Over. Keep $" << Money << " for the ride home\n";
  47.  
  48. return 0;
  49. }
  50.  
  51. void ShowIntroScreen (void) // Rules and Start Up
  52. {
  53. cout << " Welcome to Craps 1.0" << endl << endl;
  54. cout << " Here are the rules:" << endl << endl;
  55. cout << "You have 1000 dollars to start gambling. ";
  56. cout << endl << endl;
  57.  
  58. cout << "There are three types of bets. You can bet on: " << endl << endl;
  59. cout << " - 2 and 12 which will give you the ratio of 5 to 1 if you win.\n";
  60. cout << " - 4 and 10 which will give you the ratio of 2.5 to 1 if you win.\n";
  61. cout << " - 6 and 8 which will give you the ration of 1.5 and 1 if you win.";
  62. cout << endl << endl;
  63.  
  64. cout << "The minimum amount of money you can bet is 10 dollars and \n" " the highest amount of money you can bet is 100.";
  65. cout << endl << endl;
  66. cout << "Have fun playing!";
  67. cout << endl << endl;
  68.  
  69. }
  70.  
  71. void ShowInformation (unsigned long Money) // Money Display
  72. {
  73. cout << "You have : " << Money << " dollars.";
  74. cout << endl << endl;
  75. }
  76.  
  77. short GetBet (void) // Gets Bet Type
  78. {
  79. unsigned short BetType;
  80.  
  81.  
  82. cout << "Enter a type of bet ( 1 = '6/8', 2 = '4/10', 3 = '2/12': ";
  83. cin >> BetType;
  84.  
  85. if ((BetType == 1) || (BetType == 2) || (BetType == 3))
  86. {
  87. return BetType;
  88. }
  89. else
  90. {
  91. return 1;
  92. }
  93.  
  94. short DoDiceThrow (void) // Randomized Numbers
  95. {
  96. short DiceValue;
  97.  
  98.  
  99. srand (time (NULL));
  100. DiceValue = (rand () % 11) + 2;
  101.  
  102. if ((DiceValue == 4 ) || (DiceValue == 10))
  103. {
  104. srand (time (NULL));
  105. DiceValue == (rand () % 12) + 1;
  106. }
  107.  
  108. if ((DiceValue == 2) || (DiceValue == 12))
  109. {
  110. srand (time (NULL));
  111. DiceValue = (rand () % 12) + 1;
  112.  
  113. if ((DiceValue == 2) || (DiceValue == 12))
  114. {
  115. srand (time (NULL));
  116. DiceValue = (rand () % 12) + 1;
  117. }
  118. }
  119. return DiceValue;
  120. }
  121. // Calculating Data
  122. unsigned short DoMoneyCalc (short Dice, short Bet, short BetMoney)
  123. {
  124. unsigned long MoneyEarned = 0;
  125.  
  126.  
  127. switch (Bet)
  128. case 1:
  129. if ((Dice == 6) || (Dice == 8))
  130. {
  131. MoneyEarned = BetMoney * 1.5;
  132. }
  133. break; break;
  134. case 2:
  135. if ((Dice == 10) || (Dice == 4))
  136. {
  137. MoneyEarned = BetMoney * 2.5;
  138. }
  139. break; break;
  140. case 3:
  141. if ((Dice == 3) || (Dice == 12))
  142. {
  143. MoneyEarned = BetMoney * 5;
  144. }
  145. break;
  146. default;
  147. MoneyEarned = 0;
  148. break;
  149. }
  150.  
  151. return MoneyEarned;
  152. }
  153.  
  154. unsigned long GetAmount (void)
  155. {
  156. unsigned short BetAmount;
  157. cout << "Enter amount to bet (min 10 - max 100): ";
  158. cin >> BetAmount;
  159.  
  160. if (BetAmount < 10)
  161. {
  162. BetAmount = 10;
  163. }
  164.  
  165. if (BetAmount > 100)
  166. {
  167. BetAmount = 100;
  168. }
  169.  
  170. return BetAmount;
  171. }
I've had a few problems with this book already, it's about 2 years old or so, it uses an older version of c++ and there has been some
modifications over those few years. ANYWAYS!!! I need help, here are the errors!



c:\Projects\Craps\Craps.cpp(151): error C2065: 'MoneyEarned' : undeclared identifier
c:\Projects\Craps\Craps.cpp(95): error C2601: 'DoDiceThrow' : local function definitions are illegal
c:\Projects\Craps\Craps.cpp(123): error C2601: 'DoMoneyCalc' : local function definitions are illegal
c:\Projects\Craps\Craps.cpp(26): warning C4244: '=' : conversion from 'unsigned long' to 'short', possible loss of data
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Mr.PinkBunny is offline Offline
8 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Playing with inputs
Next Thread in C++ Forum Timeline: im buying a book tommorow onm C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC