Advertisement
Guest User

Untitled

a guest
Jul 13th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int displaystats(int gamesplayed, int wins, int losses, int bank);
  8.  
  9. int main()
  10. {
  11.     int bank = 100;//intital bank value
  12.     int bet = 0;//desired wager
  13.     int wins = 0;//games won
  14.     int losses = 0;//games lost
  15.     int gamesplayed = 0;//how many rounds you played
  16.     int compdice1 = 0;//first rolled dice for computer
  17.     int compdice2 = 0;//second rolled dice for computer
  18.     int playdice1 = 0;//first rolled dice for player
  19.     int playdice2 = 0;//seconds rolled dice for player
  20.     int newdice = 0;//the dice to risk your wager
  21.     int comproll = 0;//the sum of the computers roll
  22.     int playroll = 0;//the sum of the players roll
  23.  
  24.     do
  25.     {
  26.         if (bank < 0)
  27.         {
  28.             cout << "You have " << bank << " coins in your bank." << endl;
  29.             cout << "I am sorry you are out of money." << endl;
  30.             displaystats(gamesplayed, wins, losses, bank);
  31.             break;
  32.         }
  33.  
  34.         else if (bank > 0)
  35.         {
  36.             cout << "You have " << bank << " coins in your bank." << endl;
  37.             cout << "How many coins would you like to bet? ";
  38.             cin >> bet;
  39.  
  40.  
  41.             //This is the line that you forgot.
  42.             bank = bank - bet;
  43.  
  44.             compdice1 = (rand() + time(0)) % 6 + 1;//computer dice
  45.             compdice2 = (rand() + time(0)) % 6 + 1;//computer second dice
  46.             playdice1 = (rand() + time(0)) % 6 + 1;//player dice
  47.             playdice2 = (rand() + time(0)) % 6 + 1;//player second dice
  48.  
  49.             comproll = compdice1 + compdice2;//computer sum
  50.             playroll = playdice1 + playdice2;//player sume
  51.  
  52.             cout << "Your roll was " << playdice1 << " and " << playdice2 << " with a sume of " << playroll << endl;
  53.  
  54.             if (playroll < comproll)
  55.             {
  56.                 char option;//option to roll another dice
  57.  
  58.  
  59.                 cout << "You win!" << endl;
  60.                 cout << "Would you like to roll a third dice to earn 1.5 times your bet, yes or no? ";
  61.                 cin >> option;
  62.  
  63.                 if (option == 'yes')
  64.                 {
  65.                     int newroll;//the new sum of the three dice
  66.                     int newdice;//the extra roll
  67.  
  68.                     newdice = (rand() + time(0)) % 6 + 1;
  69.                     newroll = playroll + newdice;//the value of players roll
  70.  
  71.                     if (newroll > comproll)
  72.                     {
  73.                         cout << "The computer rolled " << comproll << endl;
  74.                         cout << "You now rolled higher than the computer therefore, I am sorry you lose this round." << endl;
  75.                         cout << "Your bank now equals " << bank - bet << endl;
  76.                         losses++;
  77.                         gamesplayed++;
  78.                     }
  79.  
  80.                     else if (newroll < comproll)
  81.                     {
  82.                         cout << "You win!" << endl;
  83.                         cout << "Your bank now equals " << bank + (1.5 * bet) << endl;
  84.                         wins++;
  85.                         gamesplayed++;
  86.                     }
  87.                 }
  88.                 else if (option == 'no')
  89.                 {
  90.                     cout << "Your bank now equals " << bank + bet << endl;
  91.                     wins++;
  92.                     gamesplayed++;
  93.                 }
  94.             }
  95.  
  96.             else if (playroll > comproll)
  97.             {
  98.                 cout << "The computer rolled " << comproll << endl;
  99.                 cout << "You rolled higher than the computer therefore, I am sorry you lose this round." << endl;
  100.                 cout << "Your bank now equals " << bank - bet << endl;
  101.                 losses++;
  102.                 gamesplayed++;
  103.             }
  104.  
  105.             else if (playroll = comproll)
  106.             {
  107.                 cout << "The computer also rolled " << comproll << endl;
  108.                 cout << "I am sorry you now lose double your bet!" << endl;
  109.                 cout << "Your bank now equals " << bank - (2 * bet) << endl;
  110.                 losses++;
  111.                 gamesplayed++;
  112.             }
  113.         }
  114.     } while (bank > 0);
  115.  
  116.     int stats = displaystats(gamesplayed, wins, losses, bank);
  117.  
  118.     cout << "Your stats are " << stats << endl;
  119.     return 0;
  120. }
  121.  
  122. int displaystats(int gamesplayed, int wins, int losses, int bank)
  123. {
  124.     cout << "Games Played: " << gamesplayed << endl;
  125.     cout << "Wins: " << wins << endl;
  126.     cout << "Losses: " << losses << endl;
  127.     cout << "Bank Total: " << bank << endl;
  128.  
  129.     return (gamesplayed, wins, losses, bank);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement