Advertisement
PIBogdanov

Casino

Feb 5th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include <windows.h>
  4. #include <time.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. void instructions() {
  10.     system("cls");
  11.     cout << endl << endl;
  12.     cout << " ----------------------------------------------------------------------------" << endl;
  13.     cout << " RULES OF THE GAME" << endl;
  14.     cout << " ----------------------------------------------------------------------------" << endl;
  15.     cout << " 1. Choose any number between 1 to 5" << endl;
  16.     cout << " 2. If you win you will get 10 times of money you bet" << endl;
  17.     cout << " 3. If you bet on wrong number you will lose your betting totalMoney" << endl;
  18.     cout << " ----------------------------------------------------------------------------" << endl;
  19.     cout << "Press any key to start...";
  20.     _getch();
  21. }
  22.  
  23. void play() {
  24.     system("cls");
  25.     instructions();
  26.     system("cls");
  27.  
  28.     string personName;
  29.     int totalMoney;
  30.     int betMoney;
  31.     int guess;
  32.     int dice;
  33.     char option;
  34.  
  35.     srand(time(0));
  36.  
  37.     cout << " -------------------------------------" << endl;
  38.     cout << "|           CASINO GAME             |" << endl;
  39.     cout << " -------------------------------------" << endl << endl;
  40.  
  41.     cout << "Enter Your Name : ";
  42.     getline(cin, personName);
  43.  
  44.     cout << endl << endl;
  45.     cout << "Enter Deposit Money to start game : $";
  46.     cin >> totalMoney;
  47.  
  48.     do {
  49.         system("cls");
  50.  
  51.         cout << " -------------------------------------" << endl;
  52.         cout << "|           CASINO GAME             |" << endl;
  53.         cout << " -------------------------------------" << endl << endl << endl;
  54.  
  55.         cout << "\nCurrent balance is $ " << totalMoney << endl;
  56.  
  57.         do {
  58.             cout << personName << ", Please Enter amount to bet : $";
  59.             cin >> betMoney;
  60.             if (betMoney > totalMoney)
  61.                 cout << "Betting Amount is more than current balance" << endl << "Re-enter data" << endl;
  62.  
  63.         } while (betMoney > totalMoney);
  64.  
  65.         do {
  66.             cout << "Enter Guess number to bet between 1 to 5 :";
  67.             cin >> guess;
  68.             if (guess < 1 || guess > 5)
  69.                 cout << "Number should be between 1 to 5" << endl << "Re-enter data " << endl;
  70.  
  71.         } while (guess < 1 || guess > 5);
  72.  
  73.         dice = rand() % 5 + 1;
  74.  
  75.         if (dice != guess) {
  76.             totalMoney -= betMoney;
  77.             cout << endl << endl << "You lost $ " << betMoney << endl;
  78.         }
  79.         else {
  80.             totalMoney += (betMoney * 10);
  81.             cout << endl << endl << "Congratulations!! You won Rs." << betMoney * 10;
  82.         }
  83.  
  84.         cout << "\nThe winning number was : " << dice << endl;
  85.         cout << "\n" << personName << ", You have $ " << totalMoney << endl;
  86.         if (totalMoney == 0) {
  87.             cout << "You have no money to play ";
  88.             break;
  89.         }
  90.         cout << endl << endl << " Do you want to play again (y/n)? ";
  91.         cin >> option;
  92.     } while (option == 'Y' || option == 'y');
  93.  
  94.     cout << " ----------------------------------------------------------------------------" << endl;
  95.     cout << " Thanks for playing. Your Current Money is $ " << totalMoney << endl;
  96.     cout << " ----------------------------------------------------------------------------" << endl;
  97.     _getch();
  98. }
  99.  
  100. int main() {
  101.     srand((unsigned)time(NULL));
  102.  
  103.     do {
  104.         system("cls");
  105.         cout << " -------------------------- " << endl;
  106.         cout << " |    CASINO NO GUESS     | " << endl;
  107.         cout << " --------------------------" << endl << endl;
  108.         cout << "1. Start Game" << endl;
  109.         cout << "2. Rules" << endl;
  110.         cout << "3. Quit" << endl;
  111.         cout << "Select option: ";
  112.         char op = _getche();
  113.  
  114.         if (op == '1') play();
  115.         else if (op == '2') instructions();
  116.         else if (op == '3') exit(0);
  117.  
  118.     } while (1);
  119.  
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement