Advertisement
Guest User

Rohin culm 2011

a guest
Jan 11th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.41 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <time.h>
  5. #include <windows.h>
  6.  
  7.  //cout <<"\n" <<randomNumber();
  8.     //Sleep(1000);
  9.     //cout <<"\n" <<randomNumber();
  10.     //Sleep(1000); cout<<"\b";
  11. using namespace std;
  12.  
  13. int PlayGame();
  14. void Introduction(void);
  15. void UpdateCount (int, int&, int&, int&);
  16. char AskRepeat();
  17. void Report (int, int, int);
  18. int randomNumber();//r
  19. void Goodbye(void);
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.     char selection;
  24.     Introduction();
  25.    
  26.     cout<<"Please make a selection (1-3): ";
  27.     cin >> selection;
  28.    
  29.     system("cls");
  30.    
  31.     if (selection == '1')
  32.     {
  33.        PlayGame();
  34.     }  
  35.    
  36.     //else if (selection == 2)
  37.        //UpdateCount();
  38.        
  39.     else
  40.        Goodbye();
  41.    
  42.     system("PAUSE");
  43.     return EXIT_SUCCESS;
  44. }
  45.  
  46. void Introduction(void)
  47. {
  48. cout<<"\t\t===========================================\n"
  49.     <<"\t\t\tGame of BlackJack by Rohin A.        \n"
  50.     <<"\t\t===========================================\n"
  51.    
  52.     <<"\n\n 1. Play Black Jack"
  53.     <<"  \n 2. Game Stats"
  54.     <<"\n\n 3. Quit Program\n\n\n\n\n";    
  55. }
  56.  
  57. int PlayGame()
  58. {
  59. //Plays one game of 21 and returns an indication of the winner
  60. //Post: One game has been played, and a code returned indicating the winner:
  61. //      0=draw  1=user won  2=computer won
  62.  
  63. cout<<"\nComputer's Hand...\n\n  ";
  64. int compNum[3], userNum[3];
  65.  
  66.     compNum[1] = randomNumber();  
  67.     cout<< compNum[1] <<"   "; Sleep(1000);
  68.    
  69.     compNum[2] = randomNumber();  
  70.     cout<< compNum[2] <<"   "; Sleep(1000);
  71.    
  72.     compNum[3] = randomNumber();  
  73.     cout<< compNum[3] <<"   "; Sleep(1000);
  74.    
  75.    
  76.     compNum[0] = compNum[1] + compNum[2] + compNum[3];
  77.    
  78.  
  79.     cout<<"  Total: " <<compNum[0] <<"\n\n\n\n";
  80.    
  81.     cout<<"Your Hand...\n\n  ";
  82.          userNum[1] = randomNumber();  
  83.          cout<< userNum[1] <<"   "; Sleep(1000);
  84.    
  85.          userNum[2] = randomNumber();  
  86.          cout<< userNum[2] <<"   "; Sleep(1000);
  87.    
  88.          userNum[3] = randomNumber();  
  89.          cout<< userNum[3] <<"   "; Sleep(1000);
  90.    
  91.          userNum[0] = userNum[1] + userNum[2] + userNum[3];
  92.          cout<<"  Total: " <<userNum[0] <<"\n\n";    
  93.    
  94.    
  95. }
  96.  
  97. void UpdateCount (int result, int &wins, int &losses, int&draws)
  98. {
  99. //Increment one of th counters as  determined by Result
  100. //Pre: Result is either 0, 1 or 2
  101. //Post: Either Wins, Losses, or Draws has been incremented based upon wheather Result
  102. //      is 0, 1 or 2.
  103. }
  104.  
  105. char AskRepeat()
  106. {
  107. //Asks the user if another game is desired and returns response  
  108. //Post: User has been responded with y, Y, n, or N. The response is returned  
  109. }
  110.  
  111. void Report(int Wins, int Losses, int Draws)
  112. {
  113. //Reports the current results
  114. //Pre: Wins, Losses, Draws represent the current results
  115. //Post: The current results have been displayed    
  116. }
  117.  
  118. int randomNumber()
  119. {
  120.  
  121.  
  122.   srand(time(NULL)); // This seeds the random number generator
  123.  
  124.  
  125.  
  126. int randNumber = rand(); // This gets a random number as an integer
  127. const int MAX = 10; // Sets a constant variable for the maximum
  128.  
  129.  
  130. // The MAX variable says there will be 100 numbers in the allowed
  131. // responses and the number 1 says zero will not be included
  132. int number = (randNumber % MAX) + 1;
  133.  
  134. return number; // This sends the random number back to main
  135. }
  136.  
  137. void Goodbye(void)
  138. {
  139.   system("cls");
  140.   cout<<"goodbyeeee!\n\n\n\n\n\n";    
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement