Advertisement
Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include <string>
  6. using namespace std;
  7. int numPlayer = 0; int numComp = 0;
  8. int numCount = 0 ; int numCountTwo = 0;
  9. char answer;
  10. void player(int &num1) {
  11.         num1 += rand() % 21 + 1;
  12.     cout << "\nPlayer has: " << num1 << " points";
  13. };
  14. void comp(int &num2) {
  15.             num2+=rand() % 21 + 1;
  16.         cout << "\nComp has: "<<num2<<" points.";
  17. };
  18. int main() {
  19.    
  20.     cout << "WELLCOME TO 21\n\n\n LETS START, press y for play, n for not.\n";
  21.     cin>>answer;
  22.     if (answer == 'y') {
  23.         do//game loop
  24.         {
  25.             srand(static_cast<unsigned int>(time(NULL)));
  26.             cout << "\nHit or stand? ";
  27.             cin >> answer; 
  28.             if (answer == 'y') {
  29.                 player(numPlayer);
  30.                 if (numPlayer > numComp || numComp > 13) { //komp mora imat manji broj, ili manji od 13 da bi igrao
  31.                     comp(numComp);
  32.                 }
  33.             }
  34.             else if (answer='n') {
  35.                 if (numPlayer > numComp) {
  36.                     cout << "\nPlayer has won\n";
  37.                 }
  38.                 else {
  39.                     cout << "\nComp has won.\n";
  40.                 }
  41.             }
  42.         if(numPlayer==21){
  43.             cout << "\nWinner is Player, he had: " << numPlayer << " points.\n ";
  44.             break; 
  45.             return 0;
  46.         }
  47.         else if (numPlayer>21&&numComp<21) {
  48.             cout << "\nYou lose, your num is higher than 21. \n";
  49.             cout << "Comp won, you are loser man\n.";
  50.             break;
  51.             return 0;
  52.         }
  53.         else if (numComp == 21) {
  54.             cout << "\nWinner is Comp, he had: " << numComp << " points.\n";
  55.             break;
  56.             return 0;
  57.         }
  58.         else if (numComp > 21) {
  59.             cout << "\nComp has lost.. \n";
  60.             break;
  61.             return 0;
  62.        
  63.         }
  64.         else if(numComp>21&&numPlayer>21){
  65.             cout << "\nYou both lost morons. Don't gamble.\n";
  66.             break;
  67.             return 0;
  68.         }
  69.         } while (!(numPlayer == 21 || numComp == 21));
  70.     }
  71.     else if(answer=='n') {
  72.         return 0;
  73.     }
  74.    
  75.     system("pause");
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement